--- /dev/null
+/* 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 com.owncloud.android.ui.activity;\r
+\r
+import com.actionbarsherlock.app.SherlockFragmentActivity;\r
+import com.owncloud.android.authenticator.AccountAuthenticator;\r
+import com.owncloud.android.ui.adapter.LandingScreenAdapter;\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.DialogInterface.OnClickListener;\r
+import android.content.Intent;\r
+import android.os.Bundle;\r
+import android.view.View;\r
+import android.widget.AdapterView;\r
+import android.widget.AdapterView.OnItemClickListener;\r
+import android.widget.GridView;\r
+import android.widget.Toast;\r
+import com.owncloud.android.R;\r
+\r
+/**\r
+ * This activity is used as a landing page when the user first opens this app.\r
+ * \r
+ * @author Lennart Rosam\r
+ * \r
+ */\r
+public class LandingActivity extends SherlockFragmentActivity implements\r
+ OnClickListener, OnItemClickListener {\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
+ // Fill the grid view of the landing screen with icons\r
+ GridView landingScreenItems = (GridView) findViewById(R.id.homeScreenGrid);\r
+ landingScreenItems.setAdapter(new LandingScreenAdapter(this));\r
+ landingScreenItems.setOnItemClickListener(this);\r
+\r
+ // Check, if there are ownCloud accounts\r
+ if (!accountsAreSetup()) {\r
+ showDialog(DIALOG_SETUP_ACCOUNT);\r
+ } else {\r
+ // Start device tracking service\r
+ Intent locationServiceIntent = new Intent();\r
+ locationServiceIntent\r
+ .setAction("eu.alefzero.owncloud.location.LocationLauncher");\r
+ sendBroadcast(locationServiceIntent);\r
+ }\r
+\r
+ }\r
+\r
+ @Override\r
+ protected void onRestart() {\r
+ super.onRestart();\r
+ // Check, if there are ownCloud accounts\r
+ if (!accountsAreSetup()) {\r
+ showDialog(DIALOG_SETUP_ACCOUNT);\r
+ }\r
+ }\r
+\r
+ @Override\r
+ protected void onRestoreInstanceState(Bundle savedInstanceState) {\r
+ super.onRestoreInstanceState(savedInstanceState);\r
+ // Check, if there are ownCloud accounts\r
+ if (!accountsAreSetup()) {\r
+ showDialog(DIALOG_SETUP_ACCOUNT);\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
+ 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
+ @Override\r
+ /**\r
+ * Start an activity based on the selection\r
+ * the user made\r
+ */\r
+ public void onItemClick(AdapterView<?> parent, View view, int position,\r
+ long id) {\r
+ Intent intent;\r
+ intent = (Intent) parent.getAdapter().getItem(position);\r
+ if (intent != null) {\r
+ startActivity(intent);\r
+ } else {\r
+ // TODO: Implement all of this and make this text go away ;-)\r
+ Toast toast = Toast.makeText(this, "Not yet implemented!",\r
+ Toast.LENGTH_SHORT);\r
+ toast.show();\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Checks, whether or not there are any ownCloud accounts 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