2 Copyright (C) 2014 Samsung Electronics Polska Sp. z o.o.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU AFFERO 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 You may obtain a copy of the License at
10 http://www.gnu.org/licenses/agpl-3.0.txt
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 package com.samsung.srpol.ui.tabpager;
23 import java.util.List;
25 import android.content.Context;
26 import android.os.Bundle;
27 import android.support.v4.app.Fragment;
28 import android.support.v4.app.FragmentManager;
29 import android.support.v4.app.FragmentPagerAdapter;
31 import com.samsung.srpol.data.Category;
32 import com.samsung.srpol.loader.AppListLoader;
34 public class PageAdapter extends FragmentPagerAdapter {
36 private static List<Category> mCategories;
37 private static PageFragment[] mCreatedFragments = null;
39 public PageAdapter(FragmentManager fm, Context context) {
43 public void refreshPages() {
44 if (mCategories == null) {
45 mCategories = AppListLoader.getCategories();
46 notifyDataSetChanged();
48 refreshAdapterNotify();
52 public void refreshAdapterNotify() {
53 for (PageFragment fragment : mCreatedFragments) {
55 fragment.notifyDataSetChanged();
59 public Fragment getItem(int position) {
60 if (mCreatedFragments == null)
61 mCreatedFragments = new PageFragment[mCategories.size()];
62 PageFragment f = mCreatedFragments[position];
64 f = new PageFragment();
66 Bundle args = new Bundle();
67 args.putInt("position", position);
69 mCreatedFragments[position] = f;
75 public CharSequence getPageTitle(int position) {
76 return mCategories.get(position).getTitle();
80 public int getCount() {
81 return mCategories == null ? 0 : mCategories.size();