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 eu
.alefzero
.owncloud
.ui
.fragment
;
20 import android
.content
.Context
;
21 import android
.content
.Intent
;
22 import android
.os
.Bundle
;
23 import android
.support
.v4
.app
.Fragment
;
24 import android
.view
.LayoutInflater
;
25 import android
.view
.View
;
26 import android
.view
.ViewGroup
;
27 import android
.widget
.AdapterView
;
28 import android
.widget
.BaseAdapter
;
29 import android
.widget
.GridView
;
30 import android
.widget
.ImageView
;
31 import android
.widget
.TextView
;
32 import android
.widget
.Toast
;
33 import android
.widget
.AdapterView
.OnItemClickListener
;
34 import eu
.alefzero
.owncloud
.R
;
35 import eu
.alefzero
.owncloud
.ui
.activity
.FileDisplayActivity
;
36 import eu
.alefzero
.owncloud
.ui
.activity
.Preferences
;
39 * Used on the Landing page to display what Components of
40 * the ownCloud there are. Like Files, Music, Contacts, etc.
42 * @author Lennart Rosam
45 public class LandingPageFragment
extends Fragment
implements OnItemClickListener
{
48 public View
onCreateView(LayoutInflater inflater
, ViewGroup container
,
49 Bundle savedInstanceState
) {
50 View root
= inflater
.inflate(R
.layout
.landing_page_fragment
, container
);
56 public void onActivityCreated(Bundle savedInstanceState
) {
57 super.onActivityCreated(savedInstanceState
);
58 GridView grid
= (GridView
) getView().findViewById(R
.id
.gridview
);
59 grid
.setAdapter(new LandingScreenAdapter(getActivity()));
60 grid
.setOnItemClickListener(this);
63 public void onItemClick(AdapterView
<?
> parent
, View view
, int position
, long id
) {
65 * Start an activity based on the selection
69 intent
= (Intent
) parent
.getAdapter().getItem(position
);
71 startActivity(intent
);
73 Toast toast
= Toast
.makeText(getActivity(), "Not yet implemented!", Toast
.LENGTH_SHORT
);
79 * Used to populate the landing page grid.
80 * Defined this one right in here as private class
81 * as it is unlikely that this Adapter can be useful
84 * @author Lennart Rosam
87 private class LandingScreenAdapter
extends BaseAdapter
{
89 private Context mContext
;
91 private final Integer
[] mLandingScreenIcons
= { R
.drawable
.home
,
92 R
.drawable
.music
, R
.drawable
.contacts
,
93 android
.R
.drawable
.ic_menu_today
,
94 android
.R
.drawable
.ic_menu_agenda
,
95 android
.R
.drawable
.ic_menu_preferences
};
97 private final Integer
[] mLandingScreenTexts
= { R
.string
.main_files
,
98 R
.string
.main_music
, R
.string
.main_contacts
,
99 R
.string
.main_calendar
, R
.string
.main_bookmarks
,
100 R
.string
.main_settings
};
102 public LandingScreenAdapter(Context context
) {
106 public int getCount() {
107 return mLandingScreenIcons
.length
;
111 * Returns the Intent associated with this object
112 * or null if the functionality is not yet implemented
114 public Object
getItem(int position
) {
115 Intent intent
= new Intent();
118 intent
.setClass(mContext
, FileDisplayActivity
.class);
121 intent
.setClass(mContext
, Preferences
.class);
129 public long getItemId(int position
) {
133 public View
getView(int position
, View convertView
, ViewGroup parent
) {
134 if (convertView
== null
) {
135 LayoutInflater inflator
= LayoutInflater
.from(mContext
);
136 convertView
= inflator
137 .inflate(R
.layout
.landing_page_item
, null
);
139 ImageView icon
= (ImageView
) convertView
140 .findViewById(R
.id
.gridImage
);
141 TextView iconText
= (TextView
) convertView
142 .findViewById(R
.id
.gridText
);
144 icon
.setImageResource(mLandingScreenIcons
[position
]);
145 iconText
.setText(mLandingScreenTexts
[position
]);