1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package com
.owncloud
.android
.ui
.activity
;
19 import com
.actionbarsherlock
.app
.SherlockFragmentActivity
;
20 import com
.owncloud
.android
.authenticator
.AccountAuthenticator
;
21 import com
.owncloud
.android
.ui
.adapter
.LandingScreenAdapter
;
23 import android
.accounts
.Account
;
24 import android
.accounts
.AccountManager
;
25 import android
.app
.AlertDialog
;
26 import android
.app
.Dialog
;
27 import android
.content
.DialogInterface
;
28 import android
.content
.DialogInterface
.OnClickListener
;
29 import android
.content
.Intent
;
30 import android
.os
.Bundle
;
31 import android
.view
.View
;
32 import android
.widget
.AdapterView
;
33 import android
.widget
.AdapterView
.OnItemClickListener
;
34 import android
.widget
.GridView
;
35 import android
.widget
.Toast
;
36 import com
.owncloud
.android
.R
;
39 * This activity is used as a landing page when the user first opens this app.
41 * @author Lennart Rosam
44 public class LandingActivity
extends SherlockFragmentActivity
implements
45 OnClickListener
, OnItemClickListener
{
47 public static final int DIALOG_SETUP_ACCOUNT
= 1;
50 protected void onCreate(Bundle savedInstanceState
) {
51 super.onCreate(savedInstanceState
);
52 setContentView(R
.layout
.main
);
54 // Fill the grid view of the landing screen with icons
55 GridView landingScreenItems
= (GridView
) findViewById(R
.id
.homeScreenGrid
);
56 landingScreenItems
.setAdapter(new LandingScreenAdapter(this));
57 landingScreenItems
.setOnItemClickListener(this);
59 // Check, if there are ownCloud accounts
60 if (!accountsAreSetup()) {
61 showDialog(DIALOG_SETUP_ACCOUNT
);
63 // Start device tracking service
64 Intent locationServiceIntent
= new Intent();
66 .setAction("com.owncloud.android.location.LocationLauncher");
67 sendBroadcast(locationServiceIntent
);
73 protected void onRestart() {
75 // Check, if there are ownCloud accounts
76 if (!accountsAreSetup()) {
77 showDialog(DIALOG_SETUP_ACCOUNT
);
82 protected void onRestoreInstanceState(Bundle savedInstanceState
) {
83 super.onRestoreInstanceState(savedInstanceState
);
84 // Check, if there are ownCloud accounts
85 if (!accountsAreSetup()) {
86 showDialog(DIALOG_SETUP_ACCOUNT
);
91 protected Dialog
onCreateDialog(int id
) {
94 case DIALOG_SETUP_ACCOUNT
:
95 AlertDialog
.Builder builder
= new AlertDialog
.Builder(this);
96 builder
.setTitle(R
.string
.main_tit_accsetup
);
97 builder
.setMessage(R
.string
.main_wrn_accsetup
);
98 builder
.setCancelable(false
);
99 builder
.setPositiveButton(R
.string
.common_ok
, this);
100 builder
.setNegativeButton(R
.string
.common_cancel
, this);
101 dialog
= builder
.create();
110 public void onClick(DialogInterface dialog
, int which
) {
111 // In any case - we won't need it anymore
114 case DialogInterface
.BUTTON_POSITIVE
:
115 Intent intent
= new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
116 intent
.putExtra("authorities",
117 new String
[] { AccountAuthenticator
.AUTH_TOKEN_TYPE
});
118 startActivity(intent
);
120 case DialogInterface
.BUTTON_NEGATIVE
:
128 * Start an activity based on the selection
131 public void onItemClick(AdapterView
<?
> parent
, View view
, int position
,
134 intent
= (Intent
) parent
.getAdapter().getItem(position
);
135 if (intent
!= null
) {
136 startActivity(intent
);
138 // TODO: Implement all of this and make this text go away ;-)
139 Toast toast
= Toast
.makeText(this, "Not yet implemented!",
146 * Checks, whether or not there are any ownCloud accounts setup.
148 * @return true, if there is at least one account.
150 private boolean accountsAreSetup() {
151 AccountManager accMan
= AccountManager
.get(this);
152 Account
[] accounts
= accMan
153 .getAccountsByType(AccountAuthenticator
.ACCOUNT_TYPE
);
154 return accounts
.length
> 0;