Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 1 | /* |
Alexandre Lision | c1024c0 | 2014-01-06 11:12:53 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. |
Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 3 | * |
| 4 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | * |
| 20 | * Additional permission under GNU GPL version 3 section 7: |
| 21 | * |
| 22 | * If you modify this program, or any covered work, by linking or |
| 23 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 24 | * modified version of that library), containing parts covered by the |
| 25 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 26 | * grants you additional permission to convey the resulting work. |
| 27 | * Corresponding Source for a non-source form of such a combination |
| 28 | * shall include the source code for the parts of OpenSSL used as well |
| 29 | * as that of the covered work. |
| 30 | */ |
| 31 | |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 32 | package org.sflphone.adapters; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 33 | |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 34 | import java.util.ArrayList; |
Alexandre Lision | 6e8931e | 2013-09-19 16:49:34 -0400 | [diff] [blame] | 35 | import java.util.Locale; |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 36 | |
Alexandre Lision | be54c34 | 2014-01-21 17:10:33 -0500 | [diff] [blame] | 37 | import android.support.v4.app.Fragment; |
| 38 | import android.support.v4.app.FragmentManager; |
Alexandre Lision | e5b6602 | 2013-10-30 11:34:15 -0400 | [diff] [blame] | 39 | import org.sflphone.R; |
Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 40 | import org.sflphone.fragments.CallListFragment; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 41 | import org.sflphone.fragments.DialingFragment; |
| 42 | import org.sflphone.fragments.HistoryFragment; |
Alexandre Lision | e5b6602 | 2013-10-30 11:34:15 -0400 | [diff] [blame] | 43 | import org.sflphone.views.PagerSlidingTabStrip; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 44 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 45 | import android.content.Context; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 46 | import android.util.Log; |
| 47 | |
Alexandre Lision | be54c34 | 2014-01-21 17:10:33 -0500 | [diff] [blame] | 48 | public class SectionsPagerAdapter extends android.support.v4.app.FragmentStatePagerAdapter implements PagerSlidingTabStrip.IconTabProvider { |
Alexandre Lision | e5b6602 | 2013-10-30 11:34:15 -0400 | [diff] [blame] | 49 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 50 | private static final String TAG = SectionsPagerAdapter.class.getSimpleName(); |
| 51 | Context mContext; |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 52 | ArrayList<Fragment> fragments; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 53 | |
| 54 | public SectionsPagerAdapter(Context c, FragmentManager fm) { |
| 55 | super(fm); |
| 56 | mContext = c; |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 57 | fragments = new ArrayList<Fragment>(); |
| 58 | fragments.add(new DialingFragment()); |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 59 | fragments.add(new CallListFragment()); |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 60 | fragments.add(new HistoryFragment()); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public Fragment getItem(int i) { |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 65 | |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 66 | return fragments.get(i); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 67 | } |
| 68 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 69 | public String getClassName(int i) { |
| 70 | String name; |
| 71 | |
| 72 | switch (i) { |
| 73 | case 0: |
| 74 | name = DialingFragment.class.getName(); |
| 75 | break; |
| 76 | case 1: |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 77 | name = CallListFragment.class.getName(); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 78 | break; |
| 79 | case 2: |
| 80 | name = HistoryFragment.class.getName(); |
| 81 | break; |
| 82 | |
| 83 | default: |
| 84 | Log.e(TAG, "getClassName: unknown fragment position " + i); |
| 85 | return null; |
| 86 | } |
| 87 | |
| 88 | // Log.w(TAG, "getClassName: name=" + name); |
| 89 | return name; |
| 90 | } |
| 91 | |
| 92 | @Override |
| 93 | public int getCount() { |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 94 | return fragments.size(); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 95 | } |
Alexandre Lision | e5b6602 | 2013-10-30 11:34:15 -0400 | [diff] [blame] | 96 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 97 | @Override |
| 98 | public CharSequence getPageTitle(int position) { |
Alexandre Lision | e5b6602 | 2013-10-30 11:34:15 -0400 | [diff] [blame] | 99 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 100 | switch (position) { |
| 101 | case 0: |
Alexandre Lision | 6e8931e | 2013-09-19 16:49:34 -0400 | [diff] [blame] | 102 | return mContext.getString(R.string.title_section0).toUpperCase(Locale.getDefault()); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 103 | case 1: |
Alexandre Lision | 6e8931e | 2013-09-19 16:49:34 -0400 | [diff] [blame] | 104 | return mContext.getString(R.string.title_section1).toUpperCase(Locale.getDefault()); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 105 | case 2: |
Alexandre Lision | 6e8931e | 2013-09-19 16:49:34 -0400 | [diff] [blame] | 106 | return mContext.getString(R.string.title_section2).toUpperCase(Locale.getDefault()); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 107 | default: |
| 108 | Log.e(TAG, "getPageTitle: unknown tab position " + position); |
| 109 | break; |
| 110 | } |
| 111 | return null; |
| 112 | } |
Alexandre Lision | 1a9e3b1 | 2013-09-16 11:06:07 -0400 | [diff] [blame] | 113 | |
Alexandre Lision | e5b6602 | 2013-10-30 11:34:15 -0400 | [diff] [blame] | 114 | @Override |
| 115 | public int getPageIconResId(int position) { |
| 116 | switch (position) { |
| 117 | case 0: |
| 118 | return R.drawable.ic_action_dial_pad_light; |
| 119 | case 1: |
| 120 | return R.drawable.ic_action_call; |
| 121 | case 2: |
| 122 | return R.drawable.ic_action_time; |
| 123 | default: |
| 124 | Log.e(TAG, "getPageTitle: unknown tab position " + position); |
| 125 | break; |
| 126 | } |
| 127 | return 0; |
| 128 | } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 129 | } |