2080790f7e1b16f03c1cad1801ca961d4eaaa985
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / ui / activity / LandingActivity.java
1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18 package eu.alefzero.owncloud.ui.activity;
19
20 import android.accounts.Account;
21 import android.accounts.AccountManager;
22 import android.app.AlertDialog;
23 import android.app.Dialog;
24 import android.content.DialogInterface;
25 import android.content.Intent;
26 import android.content.DialogInterface.OnClickListener;
27 import android.os.Bundle;
28 import android.support.v4.app.FragmentActivity;
29 import eu.alefzero.owncloud.R;
30 import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
31
32 /**
33 * This activity is used as a landing page when the user first opens this app.
34 * @author Lennart Rosam
35 *
36 */
37 public class LandingActivity extends FragmentActivity implements OnClickListener {
38
39 public static final int DIALOG_SETUP_ACCOUNT = 1;
40
41 @Override
42 protected void onCreate(Bundle savedInstanceState) {
43 super.onCreate(savedInstanceState);
44 setContentView(R.layout.main);
45
46 // Check, if there are ownCloud accounts
47 if(!accountsAreSetup()){
48 showDialog(DIALOG_SETUP_ACCOUNT);
49 }
50
51 }
52
53 @Override
54 protected Dialog onCreateDialog(int id) {
55 Dialog dialog;
56 switch(id){
57 case DIALOG_SETUP_ACCOUNT:
58 AlertDialog.Builder builder = new AlertDialog.Builder(this);
59 builder.setTitle(R.string.main_tit_accsetup);
60 builder.setMessage(R.string.main_wrn_accsetup);
61 builder.setCancelable(false);
62 builder.setPositiveButton(R.string.common_ok, this);
63 builder.setNegativeButton(R.string.common_cancel, this);
64 dialog = builder.create();
65 break;
66 default:
67 dialog = null;
68 }
69
70 return dialog;
71 }
72
73 public void onClick(DialogInterface dialog, int which) {
74 // In any case - we won't need it anymore
75 dialog.dismiss();
76 switch(which){
77 case DialogInterface.BUTTON_POSITIVE:
78 Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
79 intent.putExtra("authorities",
80 new String[] { AccountAuthenticator.AUTH_TOKEN_TYPE });
81 startActivity(intent);
82 break;
83 case DialogInterface.BUTTON_NEGATIVE:
84 finish();
85 }
86
87 }
88
89 /**
90 * Checks, whether or not there are any ownCloud accounts
91 * setup.
92 *
93 * @return true, if there is at least one account.
94 */
95 private boolean accountsAreSetup() {
96 AccountManager accMan = AccountManager.get(this);
97 Account[] accounts = accMan
98 .getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE);
99 return accounts.length > 0;
100 }
101
102
103 }