blob: d0e4d7594b31b14e37158b6734c6d2be8d4115c5 [file] [log] [blame]
alision84813a12013-05-27 17:40:39 -04001package com.savoirfairelinux.sflphone.adapters;
2
alision84813a12013-05-27 17:40:39 -04003import java.util.HashMap;
4
5import android.app.Fragment;
6import android.app.FragmentManager;
7import android.content.Context;
8import android.support.v13.app.FragmentStatePagerAdapter;
alisionfde875f2013-05-28 17:01:54 -04009import android.support.v4.view.PagerAdapter;
alision84813a12013-05-27 17:40:39 -040010import android.util.Log;
11
12import com.savoirfairelinux.sflphone.R;
13import com.savoirfairelinux.sflphone.fragments.CallElementListFragment;
14import com.savoirfairelinux.sflphone.fragments.CallFragment;
15import com.savoirfairelinux.sflphone.fragments.DialingFragment;
16import com.savoirfairelinux.sflphone.fragments.HistoryFragment;
17
18public class CallPagerAdapter extends FragmentStatePagerAdapter {
19
20 private static final String TAG = SectionsPagerAdapter.class.getSimpleName();
21 Context mContext;
22
23
24
25 HashMap<String,Fragment> calls;
26
27 public CallPagerAdapter(Context c, FragmentManager fm) {
28 super(fm);
29 mContext = c;
30 calls = new HashMap<String,Fragment>();
31 }
32
33 @Override
34 public Fragment getItem(int i) {
35
36 for(int j = 0 ; j <= i ; ++j){
37 calls.entrySet().iterator().next();
38 }
alisionfde875f2013-05-28 17:01:54 -040039
alision84813a12013-05-27 17:40:39 -040040 return calls.entrySet().iterator().next().getValue();
41 }
42
43// public Fragment getFragment(int i) {
44// Fragment fragment;
45//
46// switch (i) {
47// case 0:
48// fragment = new DialingFragment();
49// break;
50// case 1:
51// fragment = new CallElementListFragment();
52// break;
53// case 2:
54// fragment = new HistoryFragment();
55// break;
56// default:
57// Log.e(TAG, "getClassName: unknown fragment position " + i);
58// fragment = null;
59// }
60
61 // Log.w(TAG, "getFragment: fragment=" + fragment);
62// return fragment;
63// }
64
65 public String getClassName(int i) {
66 String name;
67
68 switch (i) {
69 case 0:
70 name = DialingFragment.class.getName();
71 break;
72 case 1:
73 name = CallElementListFragment.class.getName();
74 break;
75 case 2:
76 name = HistoryFragment.class.getName();
77 break;
78
79 default:
80 Log.e(TAG, "getClassName: unknown fragment position " + i);
81 return null;
82 }
83
84 // Log.w(TAG, "getClassName: name=" + name);
85 return name;
86 }
87
88 @Override
89 public int getCount() {
90 return calls.size();
91 }
92
93 @Override
94 public CharSequence getPageTitle(int position) {
95 switch (position) {
96 case 0:
97 return mContext.getString(R.string.title_section0).toUpperCase();
98 case 1:
99 return mContext.getString(R.string.title_section1).toUpperCase();
100 case 2:
101 return mContext.getString(R.string.title_section2).toUpperCase();
102 default:
103 Log.e(TAG, "getPageTitle: unknown tab position " + position);
104 break;
105 }
106 return null;
107 }
alisionfde875f2013-05-28 17:01:54 -0400108
109 @Override
110 public int getItemPosition(Object object){
111 return PagerAdapter.POSITION_NONE;
112 }
alision84813a12013-05-27 17:40:39 -0400113
114 public void addCall(String mCallID, CallFragment newCall) {
115 Log.w(TAG, "Put "+mCallID);
116 calls.put(mCallID,newCall);
117 notifyDataSetChanged();
118 }
119
120 public Fragment getCall(String callID) {
121 Log.w(TAG, "Get "+callID);
122 return calls.get(callID);
123
124 }
125
126 public void remove(String callID) {
alision11e8e162013-05-28 10:33:14 -0400127 calls.remove(callID);
128 notifyDataSetChanged();
alision84813a12013-05-27 17:40:39 -0400129
130 }
131}