7128886c6269b457d8e2e830f76eb5777af7ee3a
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / ui / adapter / LandingScreenAdapter.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.adapter;
19
20 import android.content.Context;
21 import android.content.Intent;
22 import android.view.LayoutInflater;
23 import android.view.View;
24 import android.view.ViewGroup;
25 import android.widget.BaseAdapter;
26 import android.widget.ImageView;
27 import android.widget.TextView;
28 import eu.alefzero.owncloud.AccountUtils;
29 import eu.alefzero.owncloud.R;
30 import eu.alefzero.owncloud.ui.activity.FileDisplayActivity;
31 import eu.alefzero.owncloud.ui.activity.Preferences;
32
33 /**
34 * Populates the landing screen icons.
35 *
36 * @author Lennart Rosam
37 *
38 */
39 public class LandingScreenAdapter extends BaseAdapter {
40
41 private Context mContext;
42
43 private final Integer[] mLandingScreenIcons = { R.drawable.home,
44 R.drawable.music, R.drawable.contacts, R.drawable.calendar,
45 android.R.drawable.ic_menu_agenda, R.drawable.settings };
46
47 private final Integer[] mLandingScreenTexts = { R.string.main_files,
48 R.string.main_music, R.string.main_contacts,
49 R.string.main_calendar, R.string.main_bookmarks,
50 R.string.main_settings };
51
52 public LandingScreenAdapter(Context context) {
53 mContext = context;
54 }
55
56 @Override
57 public int getCount() {
58 return mLandingScreenIcons.length;
59 }
60
61 @Override
62 /**
63 * Returns the Intent associated with this object
64 * or null if the functionality is not yet implemented
65 */
66 public Object getItem(int position) {
67 Intent intent = new Intent();
68
69 switch (position) {
70 case 0:
71 /*
72 * The FileDisplayActivity requires the ownCloud account as an
73 * parcableExtra. We will put in the one that is selected in the
74 * preferences
75 */
76 intent.setClass(mContext, FileDisplayActivity.class);
77 intent.putExtra("ACCOUNT",
78 AccountUtils.getCurrentOwnCloudAccount(mContext));
79 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
80 break;
81 case 5:
82 intent.setClass(mContext, Preferences.class);
83 break;
84 default:
85 intent = null;
86 }
87 return intent;
88 }
89
90 @Override
91 public long getItemId(int position) {
92 return position;
93 }
94
95 @Override
96 public View getView(int position, View convertView, ViewGroup parent) {
97 if (convertView == null) {
98 LayoutInflater inflator = LayoutInflater.from(mContext);
99 convertView = inflator.inflate(R.layout.landing_page_item, null);
100
101 ImageView icon = (ImageView) convertView
102 .findViewById(R.id.gridImage);
103 TextView iconText = (TextView) convertView
104 .findViewById(R.id.gridText);
105
106 icon.setImageResource(mLandingScreenIcons[position]);
107 iconText.setText(mLandingScreenTexts[position]);
108 }
109 return convertView;
110 }
111 }