1 package eu
.alefzero
.owncloud
.ui
.fragment
;
3 import android
.accounts
.Account
;
4 import android
.accounts
.AccountManager
;
5 import android
.content
.Context
;
6 import android
.content
.Intent
;
7 import android
.os
.Bundle
;
8 import android
.support
.v4
.app
.Fragment
;
9 import android
.util
.Log
;
10 import android
.view
.LayoutInflater
;
11 import android
.view
.View
;
12 import android
.view
.ViewGroup
;
13 import android
.widget
.AdapterView
;
14 import android
.widget
.AdapterView
.OnItemClickListener
;
15 import android
.widget
.BaseAdapter
;
16 import android
.widget
.GridView
;
17 import android
.widget
.ImageView
;
18 import android
.widget
.TextView
;
19 import android
.widget
.Toast
;
20 import eu
.alefzero
.owncloud
.R
;
21 import eu
.alefzero
.owncloud
.authenticator
.AccountAuthenticator
;
22 import eu
.alefzero
.owncloud
.ui
.FileDisplayActivity
;
23 import eu
.alefzero
.owncloud
.ui
.Preferences
;
25 public class LandingPageFragment
extends Fragment
implements OnItemClickListener
{
28 public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
29 Bundle savedInstanceState
) {
30 View root
= inflater
.inflate(R
.layout
.landing_page_fragment
, container
);
36 public void onActivityCreated(Bundle savedInstanceState
) {
37 super.onActivityCreated(savedInstanceState
);
38 GridView grid
= (GridView
) getView().findViewById(R
.id
.gridview
);
39 grid
.setAdapter(new LandingScreenAdapter(getActivity()));
40 grid
.setOnItemClickListener(this);
44 public void onItemClick(AdapterView
<?
> parent
, View view
, int position
, long id
) {
48 * If the user selects something and acounts are setup,
49 * we can use our LandingScreenAdapter to get the matching
50 * intent for the selected item.
52 * Otherwise, the accounsAreSetuo() method will trigger the
55 if(accountsAreSetup()){
56 intent
= (Intent
) parent
.getAdapter().getItem(position
);
58 startActivity(intent
);
60 Toast toast
= Toast
.makeText(getActivity(), "Not yet implemented!", Toast
.LENGTH_SHORT
);
68 * Checks, whether or not there are any ownCloud accounts
69 * setup. If there is none, it will create one.
71 * If there are more then one, it will trigger a selection
72 * unless the selection has not been made yet.
74 * @return true, if there is at least one account.
76 private boolean accountsAreSetup() {
77 AccountManager accMan
= AccountManager
.get(getActivity());
78 Account
[] accounts
= accMan
79 .getAccountsByType(AccountAuthenticator
.ACCOUNT_TYPE
);
81 if (accounts
.length
== 0) {
82 Intent intent
= new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
83 intent
.putExtra("authorities",
84 new String
[] { AccountAuthenticator
.AUTH_TOKEN_TYPE
});
85 startActivity(intent
);
87 } else if (accounts
.length
> 1) {
88 // TODO: Figure out what to do.
95 * Used to populate the landing page grid.
96 * Defined this one right in here as private class
97 * as it is unlikely that this Adapter can be useful
100 * @author Lennart Rosam
103 private class LandingScreenAdapter
extends BaseAdapter
{
105 private Context mContext
;
107 private final Integer
[] mLandingScreenIcons
= { R
.drawable
.home
,
108 R
.drawable
.music
, R
.drawable
.contacts
,
109 android
.R
.drawable
.ic_menu_today
,
110 android
.R
.drawable
.ic_menu_agenda
,
111 android
.R
.drawable
.ic_menu_preferences
};
113 private final Integer
[] mLandingScreenTexts
= { R
.string
.main_files
,
114 R
.string
.main_music
, R
.string
.main_contacts
,
115 R
.string
.main_calendar
, R
.string
.main_bookmarks
,
116 R
.string
.main_settings
};
118 public LandingScreenAdapter(Context context
) {
123 public int getCount() {
124 return mLandingScreenIcons
.length
;
129 * Returns the Intent associated with this object
130 * or null if the functionality is not yet implemented
132 public Object
getItem(int position
) {
133 Intent intent
= new Intent();
136 intent
.setClass(mContext
, FileDisplayActivity
.class);
139 intent
.setClass(mContext
, Preferences
.class);
148 public long getItemId(int position
) {
153 public View
getView(int position
, View convertView
, ViewGroup parent
) {
154 if (convertView
== null
) {
155 LayoutInflater inflator
= LayoutInflater
.from(mContext
);
156 convertView
= inflator
157 .inflate(R
.layout
.landing_page_item
, null
);
159 ImageView icon
= (ImageView
) convertView
160 .findViewById(R
.id
.gridImage
);
161 TextView iconText
= (TextView
) convertView
162 .findViewById(R
.id
.gridText
);
164 icon
.setImageResource(mLandingScreenIcons
[position
]);
165 iconText
.setText(mLandingScreenTexts
[position
]);