ssl support for syncing
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / ui / fragment / LandingPageFragment.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.fragment;
19
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;
37
38 /**
39 * Used on the Landing page to display what Components of
40 * the ownCloud there are. Like Files, Music, Contacts, etc.
41 *
42 * @author Lennart Rosam
43 *
44 */
45 public class LandingPageFragment extends Fragment implements OnItemClickListener {
46
47 @Override
48 public View onCreateView(LayoutInflater inflater, ViewGroup container,
49 Bundle savedInstanceState) {
50 View root = inflater.inflate(R.layout.landing_page_fragment, container);
51 return root;
52 }
53
54
55 @Override
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);
61 }
62
63 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
64 /*
65 * Start an activity based on the selection
66 * the user made
67 */
68 Intent intent;
69 intent = (Intent) parent.getAdapter().getItem(position);
70 if(intent != null ){
71 startActivity(intent);
72 } else {
73 Toast toast = Toast.makeText(getActivity(), "Not yet implemented!", Toast.LENGTH_SHORT);
74 toast.show();
75 }
76 }
77
78 /**
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
82 * anywhere else.
83 *
84 * @author Lennart Rosam
85 *
86 */
87 private class LandingScreenAdapter extends BaseAdapter {
88
89 private Context mContext;
90
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 };
96
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 };
101
102 public LandingScreenAdapter(Context context) {
103 mContext = context;
104 }
105
106 public int getCount() {
107 return mLandingScreenIcons.length;
108 }
109
110 /**
111 * Returns the Intent associated with this object
112 * or null if the functionality is not yet implemented
113 */
114 public Object getItem(int position) {
115 Intent intent = new Intent();
116 switch (position) {
117 case 0:
118 intent.setClass(mContext, FileDisplayActivity.class);
119 break;
120 case 5:
121 intent.setClass(mContext, Preferences.class);
122 break;
123 default:
124 intent = null;
125 }
126 return intent;
127 }
128
129 public long getItemId(int position) {
130 return position;
131 }
132
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);
138
139 ImageView icon = (ImageView) convertView
140 .findViewById(R.id.gridImage);
141 TextView iconText = (TextView) convertView
142 .findViewById(R.id.gridText);
143
144 icon.setImageResource(mLandingScreenIcons[position]);
145 iconText.setText(mLandingScreenTexts[position]);
146 }
147 return convertView;
148 }
149 }
150
151
152
153 }