Disable change log; to remove in future
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / adapter / LandingScreenAdapter.java
1 /* ownCloud Android client application
2 * Copyright (C) 2011 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19 package com.owncloud.android.ui.adapter;
20
21 import com.owncloud.android.AccountUtils;
22 import com.owncloud.android.ui.activity.FileDisplayActivity;
23 import com.owncloud.android.ui.activity.Preferences;
24
25 import android.content.Context;
26 import android.content.Intent;
27 import android.view.LayoutInflater;
28 import android.view.View;
29 import android.view.ViewGroup;
30 import android.widget.BaseAdapter;
31 import android.widget.ImageView;
32 import android.widget.TextView;
33 import com.owncloud.android.R;
34
35 /**
36 * Populates the landing screen icons.
37 *
38 * @author Lennart Rosam
39 *
40 */
41 public class LandingScreenAdapter extends BaseAdapter {
42
43 private Context mContext;
44
45 private final Integer[] mLandingScreenIcons = { R.drawable.home,
46 R.drawable.music, R.drawable.contacts, R.drawable.calendar,
47 android.R.drawable.ic_menu_agenda, R.drawable.settings };
48
49 private final Integer[] mLandingScreenTexts = { R.string.main_files,
50 R.string.main_music, R.string.main_contacts,
51 R.string.main_calendar, R.string.main_bookmarks,
52 R.string.main_settings };
53
54 public LandingScreenAdapter(Context context) {
55 mContext = context;
56 }
57
58 @Override
59 public int getCount() {
60 return mLandingScreenIcons.length;
61 }
62
63 @Override
64 /**
65 * Returns the Intent associated with this object
66 * or null if the functionality is not yet implemented
67 */
68 public Object getItem(int position) {
69 Intent intent = new Intent();
70
71 switch (position) {
72 case 0:
73 /*
74 * The FileDisplayActivity requires the ownCloud account as an
75 * parcableExtra. We will put in the one that is selected in the
76 * preferences
77 */
78 intent.setClass(mContext, FileDisplayActivity.class);
79 intent.putExtra("ACCOUNT",
80 AccountUtils.getCurrentOwnCloudAccount(mContext));
81 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
82 break;
83 case 5:
84 intent.setClass(mContext, Preferences.class);
85 break;
86 default:
87 intent = null;
88 }
89 return intent;
90 }
91
92 @Override
93 public long getItemId(int position) {
94 return position;
95 }
96
97 @Override
98 public View getView(int position, View convertView, ViewGroup parent) {
99 if (convertView == null) {
100 LayoutInflater inflator = LayoutInflater.from(mContext);
101 convertView = inflator.inflate(R.layout.landing_page_item, null);
102
103 ImageView icon = (ImageView) convertView
104 .findViewById(R.id.gridImage);
105 TextView iconText = (TextView) convertView
106 .findViewById(R.id.gridText);
107
108 icon.setImageResource(mLandingScreenIcons[position]);
109 iconText.setText(mLandingScreenTexts[position]);
110 }
111 return convertView;
112 }
113 }