blob: 485c005300ba8ea87310db639294ac695c14b4fb [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 Lisionb4e60612014-01-14 17:47:23 -050037import android.app.Fragment;
38import android.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;
Alexandre Lision1a9e3b12013-09-16 11:06:07 -040046import android.os.RemoteException;
alision9f7a6ec2013-05-24 16:26:26 -040047import android.util.Log;
48
Alexandre Lisionb4e60612014-01-14 17:47:23 -050049public class SectionsPagerAdapter extends android.support.v13.app.FragmentStatePagerAdapter implements PagerSlidingTabStrip.IconTabProvider {
Alexandre Lisione5b66022013-10-30 11:34:15 -040050
alision9f7a6ec2013-05-24 16:26:26 -040051 private static final String TAG = SectionsPagerAdapter.class.getSimpleName();
52 Context mContext;
alision58356b72013-06-03 17:13:36 -040053 ArrayList<Fragment> fragments;
alision9f7a6ec2013-05-24 16:26:26 -040054
55 public SectionsPagerAdapter(Context c, FragmentManager fm) {
56 super(fm);
57 mContext = c;
alision58356b72013-06-03 17:13:36 -040058 fragments = new ArrayList<Fragment>();
59 fragments.add(new DialingFragment());
Alexandre Lisionf02190d2013-12-12 17:26:12 -050060 fragments.add(new CallListFragment());
alision58356b72013-06-03 17:13:36 -040061 fragments.add(new HistoryFragment());
alision9f7a6ec2013-05-24 16:26:26 -040062 }
63
64 @Override
65 public Fragment getItem(int i) {
alision9f7a6ec2013-05-24 16:26:26 -040066
alision58356b72013-06-03 17:13:36 -040067 return fragments.get(i);
alision9f7a6ec2013-05-24 16:26:26 -040068 }
69
alision9f7a6ec2013-05-24 16:26:26 -040070 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 Lisionf02190d2013-12-12 17:26:12 -050078 name = CallListFragment.class.getName();
alision9f7a6ec2013-05-24 16:26:26 -040079 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 Lisionafd40e42013-10-15 13:48:37 -040095 return fragments.size();
alision9f7a6ec2013-05-24 16:26:26 -040096 }
Alexandre Lisione5b66022013-10-30 11:34:15 -040097
alision9f7a6ec2013-05-24 16:26:26 -040098 @Override
99 public CharSequence getPageTitle(int position) {
Alexandre Lisione5b66022013-10-30 11:34:15 -0400100
alision9f7a6ec2013-05-24 16:26:26 -0400101 switch (position) {
102 case 0:
Alexandre Lision6e8931e2013-09-19 16:49:34 -0400103 return mContext.getString(R.string.title_section0).toUpperCase(Locale.getDefault());
alision9f7a6ec2013-05-24 16:26:26 -0400104 case 1:
Alexandre Lision6e8931e2013-09-19 16:49:34 -0400105 return mContext.getString(R.string.title_section1).toUpperCase(Locale.getDefault());
alision9f7a6ec2013-05-24 16:26:26 -0400106 case 2:
Alexandre Lision6e8931e2013-09-19 16:49:34 -0400107 return mContext.getString(R.string.title_section2).toUpperCase(Locale.getDefault());
alision9f7a6ec2013-05-24 16:26:26 -0400108 default:
109 Log.e(TAG, "getPageTitle: unknown tab position " + position);
110 break;
111 }
112 return null;
113 }
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400114
115 public void updateHome() {
116 try {
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500117 ((CallListFragment) fragments.get(1)).updateLists();
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400118 } catch (RemoteException e) {
119 e.printStackTrace();
Alexandre Lisione5b66022013-10-30 11:34:15 -0400120 } catch (Exception e1) {
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400121 e1.printStackTrace();
122 }
123 }
Alexandre Lisione5b66022013-10-30 11:34:15 -0400124
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 }
alision9f7a6ec2013-05-24 16:26:26 -0400140}