blob: 3c1da6876b3600dda10e09f7ddb255923122702e [file] [log] [blame]
Alexandre Lisiona8b78722013-12-13 10:18:33 -05001/*
Alexandre Lisionc1024c02014-01-06 11:12:53 -05002 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
Alexandre Lisiona8b78722013-12-13 10:18:33 -05003 *
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 Lision064e1e02013-10-01 16:18:42 -040032package org.sflphone.adapters;
alision9f7a6ec2013-05-24 16:26:26 -040033
alision58356b72013-06-03 17:13:36 -040034import java.util.ArrayList;
Alexandre Lision6e8931e2013-09-19 16:49:34 -040035import java.util.Locale;
alision58356b72013-06-03 17:13:36 -040036
Alexandre Lisionbe54c342014-01-21 17:10:33 -050037import android.support.v4.app.Fragment;
38import android.support.v4.app.FragmentManager;
Alexandre Lisione5b66022013-10-30 11:34:15 -040039import org.sflphone.R;
Alexandre Lisiona8b78722013-12-13 10:18:33 -050040import org.sflphone.fragments.CallListFragment;
Alexandre Lision064e1e02013-10-01 16:18:42 -040041import org.sflphone.fragments.DialingFragment;
42import org.sflphone.fragments.HistoryFragment;
Alexandre Lisione5b66022013-10-30 11:34:15 -040043import org.sflphone.views.PagerSlidingTabStrip;
Alexandre Lision064e1e02013-10-01 16:18:42 -040044
alision9f7a6ec2013-05-24 16:26:26 -040045import android.content.Context;
alision9f7a6ec2013-05-24 16:26:26 -040046import android.util.Log;
47
Alexandre Lisionbe54c342014-01-21 17:10:33 -050048public class SectionsPagerAdapter extends android.support.v4.app.FragmentStatePagerAdapter implements PagerSlidingTabStrip.IconTabProvider {
Alexandre Lisione5b66022013-10-30 11:34:15 -040049
alision9f7a6ec2013-05-24 16:26:26 -040050 private static final String TAG = SectionsPagerAdapter.class.getSimpleName();
51 Context mContext;
alision58356b72013-06-03 17:13:36 -040052 ArrayList<Fragment> fragments;
alision9f7a6ec2013-05-24 16:26:26 -040053
54 public SectionsPagerAdapter(Context c, FragmentManager fm) {
55 super(fm);
56 mContext = c;
alision58356b72013-06-03 17:13:36 -040057 fragments = new ArrayList<Fragment>();
58 fragments.add(new DialingFragment());
Alexandre Lisionf02190d2013-12-12 17:26:12 -050059 fragments.add(new CallListFragment());
alision58356b72013-06-03 17:13:36 -040060 fragments.add(new HistoryFragment());
alision9f7a6ec2013-05-24 16:26:26 -040061 }
62
63 @Override
64 public Fragment getItem(int i) {
alision9f7a6ec2013-05-24 16:26:26 -040065
alision58356b72013-06-03 17:13:36 -040066 return fragments.get(i);
alision9f7a6ec2013-05-24 16:26:26 -040067 }
68
alision9f7a6ec2013-05-24 16:26:26 -040069 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 Lisionf02190d2013-12-12 17:26:12 -050077 name = CallListFragment.class.getName();
alision9f7a6ec2013-05-24 16:26:26 -040078 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 Lisionafd40e42013-10-15 13:48:37 -040094 return fragments.size();
alision9f7a6ec2013-05-24 16:26:26 -040095 }
Alexandre Lisione5b66022013-10-30 11:34:15 -040096
alision9f7a6ec2013-05-24 16:26:26 -040097 @Override
98 public CharSequence getPageTitle(int position) {
Alexandre Lisione5b66022013-10-30 11:34:15 -040099
alision9f7a6ec2013-05-24 16:26:26 -0400100 switch (position) {
101 case 0:
Alexandre Lision6e8931e2013-09-19 16:49:34 -0400102 return mContext.getString(R.string.title_section0).toUpperCase(Locale.getDefault());
alision9f7a6ec2013-05-24 16:26:26 -0400103 case 1:
Alexandre Lision6e8931e2013-09-19 16:49:34 -0400104 return mContext.getString(R.string.title_section1).toUpperCase(Locale.getDefault());
alision9f7a6ec2013-05-24 16:26:26 -0400105 case 2:
Alexandre Lision6e8931e2013-09-19 16:49:34 -0400106 return mContext.getString(R.string.title_section2).toUpperCase(Locale.getDefault());
alision9f7a6ec2013-05-24 16:26:26 -0400107 default:
108 Log.e(TAG, "getPageTitle: unknown tab position " + position);
109 break;
110 }
111 return null;
112 }
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400113
Alexandre Lisione5b66022013-10-30 11:34:15 -0400114 @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 }
alision9f7a6ec2013-05-24 16:26:26 -0400129}