LandingScreenAdapter.java 3.7 KB

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