*/\r
package eu.alefzero.owncloud.ui.fragment;\r
\r
+import android.content.Context;\r
import android.content.Intent;\r
import android.os.Bundle;\r
import android.support.v4.app.Fragment;\r
import android.view.View;\r
import android.view.ViewGroup;\r
import android.widget.AdapterView;\r
-import android.widget.AdapterView.OnItemClickListener;\r
+import android.widget.BaseAdapter;\r
import android.widget.GridView;\r
+import android.widget.ImageView;\r
+import android.widget.TextView;\r
import android.widget.Toast;\r
+import android.widget.AdapterView.OnItemClickListener;\r
import eu.alefzero.owncloud.R;\r
-import eu.alefzero.owncloud.ui.adapter.LandingScreenAdapter;\r
+import eu.alefzero.owncloud.ui.activity.FileDisplayActivity;\r
+import eu.alefzero.owncloud.ui.activity.Preferences;\r
\r
/**\r
* Used on the Landing page to display what Components of \r
grid.setOnItemClickListener(this);\r
}\r
\r
- @Override\r
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {\r
/*\r
* Start an activity based on the selection\r
Intent intent;\r
intent = (Intent) parent.getAdapter().getItem(position);\r
if(intent != null ){\r
- startActivity(intent);\r
+ startActivity(intent);
} else {\r
Toast toast = Toast.makeText(getActivity(), "Not yet implemented!", Toast.LENGTH_SHORT);\r
toast.show();\r
+ } \r
+ }\r
+\r
+ /**\r
+ * Used to populate the landing page grid.\r
+ * Defined this one right in here as private class\r
+ * as it is unlikely that this Adapter can be useful\r
+ * anywhere else.\r
+ * \r
+ * @author Lennart Rosam\r
+ *\r
+ */\r
+ private class LandingScreenAdapter extends BaseAdapter {\r
+\r
+ private Context mContext;\r
+\r
+ private final Integer[] mLandingScreenIcons = { R.drawable.home,\r
+ R.drawable.music, R.drawable.contacts,\r
+ android.R.drawable.ic_menu_today,\r
+ android.R.drawable.ic_menu_agenda,\r
+ android.R.drawable.ic_menu_preferences };\r
+\r
+ private final Integer[] mLandingScreenTexts = { R.string.main_files,\r
+ R.string.main_music, R.string.main_contacts,\r
+ R.string.main_calendar, R.string.main_bookmarks,\r
+ R.string.main_settings };\r
+\r
+ public LandingScreenAdapter(Context context) {\r
+ mContext = context;\r
+ }\r
+\r
+ public int getCount() {\r
+ return mLandingScreenIcons.length;\r
+ }\r
+\r
+ /**\r
+ * Returns the Intent associated with this object\r
+ * or null if the functionality is not yet implemented\r
+ */\r
+ public Object getItem(int position) {\r
+ Intent intent = new Intent();\r
+ switch (position) {\r
+ case 0:\r
+ intent.setClass(mContext, FileDisplayActivity.class);\r
+ break;\r
+ case 5:\r
+ intent.setClass(mContext, Preferences.class);\r
+ break;\r
+ default:\r
+ intent = null;\r
+ }\r
+ return intent;\r
+ }\r
+\r
+ public long getItemId(int position) {\r
+ return position;\r
+ }\r
+\r
+ public View getView(int position, View convertView, ViewGroup parent) {\r
+ if (convertView == null) {\r
+ LayoutInflater inflator = LayoutInflater.from(mContext);\r
+ convertView = inflator\r
+ .inflate(R.layout.landing_page_item, null);\r
+\r
+ ImageView icon = (ImageView) convertView\r
+ .findViewById(R.id.gridImage);\r
+ TextView iconText = (TextView) convertView\r
+ .findViewById(R.id.gridText);\r
+\r
+ icon.setImageResource(mLandingScreenIcons[position]);\r
+ iconText.setText(mLandingScreenTexts[position]);\r
+ }\r
+ return convertView;
}\r
}\r
\r