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 | e5b6602 | 2013-10-30 11:34:15 -0400 | [diff] [blame] | 37 | import org.sflphone.R; |
Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 38 | import org.sflphone.fragments.CallListFragment; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 39 | import org.sflphone.fragments.DialingFragment; |
| 40 | import org.sflphone.fragments.HistoryFragment; |
Alexandre Lision | e5b6602 | 2013-10-30 11:34:15 -0400 | [diff] [blame] | 41 | import org.sflphone.views.PagerSlidingTabStrip; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 42 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 43 | import android.content.Context; |
Alexandre Lision | 1a9e3b1 | 2013-09-16 11:06:07 -0400 | [diff] [blame] | 44 | import android.os.RemoteException; |
Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 45 | import android.support.v4.app.Fragment; |
| 46 | import android.support.v4.app.FragmentManager; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 47 | import android.util.Log; |
| 48 | |
Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 49 | public class SectionsPagerAdapter extends android.support.v4.app.FragmentStatePagerAdapter implements PagerSlidingTabStrip.IconTabProvider { |
Alexandre Lision | e5b6602 | 2013-10-30 11:34:15 -0400 | [diff] [blame] | 50 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 51 | private static final String TAG = SectionsPagerAdapter.class.getSimpleName(); |
| 52 | Context mContext; |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 53 | ArrayList<Fragment> fragments; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 54 | |
| 55 | public SectionsPagerAdapter(Context c, FragmentManager fm) { |
| 56 | super(fm); |
| 57 | mContext = c; |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 58 | fragments = new ArrayList<Fragment>(); |
| 59 | fragments.add(new DialingFragment()); |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 60 | fragments.add(new CallListFragment()); |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 61 | fragments.add(new HistoryFragment()); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public Fragment getItem(int i) { |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 66 | |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 67 | return fragments.get(i); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 68 | } |
| 69 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 70 | public String getClassName(int i) { |
| 71 | String name; |
| 72 | |
| 73 | switch (i) { |
| 74 | case 0: |
| 75 | name = DialingFragment.class.getName(); |
| 76 | break; |
| 77 | case 1: |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 78 | name = CallListFragment.class.getName(); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 79 | break; |
| 80 | case 2: |
| 81 | name = HistoryFragment.class.getName(); |
| 82 | break; |
| 83 | |
| 84 | default: |
| 85 | Log.e(TAG, "getClassName: unknown fragment position " + i); |
| 86 | return null; |
| 87 | } |
| 88 | |
| 89 | // Log.w(TAG, "getClassName: name=" + name); |
| 90 | return name; |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public int getCount() { |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 95 | return fragments.size(); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 96 | } |
Alexandre Lision | e5b6602 | 2013-10-30 11:34:15 -0400 | [diff] [blame] | 97 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 98 | @Override |
| 99 | public CharSequence getPageTitle(int position) { |
Alexandre Lision | e5b6602 | 2013-10-30 11:34:15 -0400 | [diff] [blame] | 100 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 101 | switch (position) { |
| 102 | case 0: |
Alexandre Lision | 6e8931e | 2013-09-19 16:49:34 -0400 | [diff] [blame] | 103 | return mContext.getString(R.string.title_section0).toUpperCase(Locale.getDefault()); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 104 | case 1: |
Alexandre Lision | 6e8931e | 2013-09-19 16:49:34 -0400 | [diff] [blame] | 105 | return mContext.getString(R.string.title_section1).toUpperCase(Locale.getDefault()); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 106 | case 2: |
Alexandre Lision | 6e8931e | 2013-09-19 16:49:34 -0400 | [diff] [blame] | 107 | return mContext.getString(R.string.title_section2).toUpperCase(Locale.getDefault()); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 108 | default: |
| 109 | Log.e(TAG, "getPageTitle: unknown tab position " + position); |
| 110 | break; |
| 111 | } |
| 112 | return null; |
| 113 | } |
Alexandre Lision | 1a9e3b1 | 2013-09-16 11:06:07 -0400 | [diff] [blame] | 114 | |
| 115 | public void updateHome() { |
| 116 | try { |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 117 | ((CallListFragment) fragments.get(1)).updateLists(); |
Alexandre Lision | 1a9e3b1 | 2013-09-16 11:06:07 -0400 | [diff] [blame] | 118 | } catch (RemoteException e) { |
| 119 | e.printStackTrace(); |
Alexandre Lision | e5b6602 | 2013-10-30 11:34:15 -0400 | [diff] [blame] | 120 | } catch (Exception e1) { |
Alexandre Lision | 1a9e3b1 | 2013-09-16 11:06:07 -0400 | [diff] [blame] | 121 | e1.printStackTrace(); |
| 122 | } |
| 123 | } |
Alexandre Lision | e5b6602 | 2013-10-30 11:34:15 -0400 | [diff] [blame] | 124 | |
| 125 | @Override |
| 126 | public int getPageIconResId(int position) { |
| 127 | switch (position) { |
| 128 | case 0: |
| 129 | return R.drawable.ic_action_dial_pad_light; |
| 130 | case 1: |
| 131 | return R.drawable.ic_action_call; |
| 132 | case 2: |
| 133 | return R.drawable.ic_action_time; |
| 134 | default: |
| 135 | Log.e(TAG, "getPageTitle: unknown tab position " + position); |
| 136 | break; |
| 137 | } |
| 138 | return 0; |
| 139 | } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 140 | } |