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 as published by 
   6  *   the Free Software Foundation, either version 3 of the License, or 
   7  *   (at your option) any later version. 
   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. 
  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/>. 
  18 package com
.owncloud
.android
.ui
.activity
; 
  20 import com
.actionbarsherlock
.app
.SherlockFragmentActivity
; 
  21 import com
.owncloud
.android
.authenticator
.AccountAuthenticator
; 
  22 import com
.owncloud
.android
.ui
.adapter
.LandingScreenAdapter
; 
  24 import android
.accounts
.Account
; 
  25 import android
.accounts
.AccountManager
; 
  26 import android
.app
.AlertDialog
; 
  27 import android
.app
.Dialog
; 
  28 import android
.content
.DialogInterface
; 
  29 import android
.content
.DialogInterface
.OnClickListener
; 
  30 import android
.content
.Intent
; 
  31 import android
.os
.Bundle
; 
  32 import android
.view
.View
; 
  33 import android
.widget
.AdapterView
; 
  34 import android
.widget
.AdapterView
.OnItemClickListener
; 
  35 import android
.widget
.GridView
; 
  36 import android
.widget
.Toast
; 
  37 import com
.owncloud
.android
.R
; 
  40  * This activity is used as a landing page when the user first opens this app. 
  42  * @author Lennart Rosam 
  45 public class LandingActivity 
extends SherlockFragmentActivity 
implements 
  46         OnClickListener
, OnItemClickListener 
{ 
  48     public static final int DIALOG_SETUP_ACCOUNT 
= 1; 
  51     protected void onCreate(Bundle savedInstanceState
) { 
  52         super.onCreate(savedInstanceState
); 
  53         setContentView(R
.layout
.main
); 
  55         // Fill the grid view of the landing screen with icons 
  56         GridView landingScreenItems 
= (GridView
) findViewById(R
.id
.homeScreenGrid
); 
  57         landingScreenItems
.setAdapter(new LandingScreenAdapter(this)); 
  58         landingScreenItems
.setOnItemClickListener(this); 
  60         // Check, if there are ownCloud accounts 
  61         if (!accountsAreSetup()) { 
  62             showDialog(DIALOG_SETUP_ACCOUNT
); 
  64             // Start device tracking service 
  65             Intent locationServiceIntent 
= new Intent(); 
  67                     .setAction("com.owncloud.android.location.LocationLauncher"); 
  68             sendBroadcast(locationServiceIntent
); 
  74     protected void onRestart() { 
  76         // Check, if there are ownCloud accounts 
  77         if (!accountsAreSetup()) { 
  78             showDialog(DIALOG_SETUP_ACCOUNT
); 
  83     protected void onRestoreInstanceState(Bundle savedInstanceState
) { 
  84         super.onRestoreInstanceState(savedInstanceState
); 
  85         // Check, if there are ownCloud accounts 
  86         if (!accountsAreSetup()) { 
  87             showDialog(DIALOG_SETUP_ACCOUNT
); 
  92     protected Dialog 
onCreateDialog(int id
) { 
  95         case DIALOG_SETUP_ACCOUNT
: 
  96             AlertDialog
.Builder builder 
= new AlertDialog
.Builder(this); 
  97             builder
.setTitle(R
.string
.main_tit_accsetup
); 
  98             builder
.setMessage(R
.string
.main_wrn_accsetup
); 
  99             builder
.setCancelable(false
); 
 100             builder
.setPositiveButton(R
.string
.common_ok
, this); 
 101             builder
.setNegativeButton(R
.string
.common_cancel
, this); 
 102             dialog 
= builder
.create(); 
 111     public void onClick(DialogInterface dialog
, int which
) { 
 112         // In any case - we won't need it anymore 
 115         case DialogInterface
.BUTTON_POSITIVE
: 
 116             Intent intent 
= new Intent("android.settings.ADD_ACCOUNT_SETTINGS"); 
 117             intent
.putExtra("authorities", 
 118                     new String
[] { AccountAuthenticator
.AUTH_TOKEN_TYPE 
}); 
 119             startActivity(intent
); 
 121         case DialogInterface
.BUTTON_NEGATIVE
: 
 129      * Start an activity based on the selection 
 132     public void onItemClick(AdapterView
<?
> parent
, View view
, int position
, 
 135         intent 
= (Intent
) parent
.getAdapter().getItem(position
); 
 136         if (intent 
!= null
) { 
 137             startActivity(intent
); 
 139             // TODO: Implement all of this and make this text go away ;-) 
 140             Toast toast 
= Toast
.makeText(this, "Not yet implemented!", 
 147      * Checks, whether or not there are any ownCloud accounts setup. 
 149      * @return true, if there is at least one account. 
 151     private boolean accountsAreSetup() { 
 152         AccountManager accMan 
= AccountManager
.get(this); 
 153         Account
[] accounts 
= accMan
 
 154                 .getAccountsByType(AccountAuthenticator
.ACCOUNT_TYPE
); 
 155         return accounts
.length 
> 0;