alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 1 | package com.savoirfairelinux.sflphone.adapters; |
| 2 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 3 | import java.util.HashMap; |
| 4 | |
| 5 | import android.app.Fragment; |
| 6 | import android.app.FragmentManager; |
| 7 | import android.content.Context; |
| 8 | import android.support.v13.app.FragmentStatePagerAdapter; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 9 | import android.support.v4.view.PagerAdapter; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 10 | import android.util.Log; |
| 11 | |
| 12 | import com.savoirfairelinux.sflphone.R; |
| 13 | import com.savoirfairelinux.sflphone.fragments.CallElementListFragment; |
| 14 | import com.savoirfairelinux.sflphone.fragments.CallFragment; |
| 15 | import com.savoirfairelinux.sflphone.fragments.DialingFragment; |
| 16 | import com.savoirfairelinux.sflphone.fragments.HistoryFragment; |
| 17 | |
| 18 | public 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 | } |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 39 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 40 | 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 | } |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 108 | |
| 109 | @Override |
| 110 | public int getItemPosition(Object object){ |
| 111 | return PagerAdapter.POSITION_NONE; |
| 112 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 113 | |
| 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) { |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 127 | calls.remove(callID); |
| 128 | notifyDataSetChanged(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 129 | |
| 130 | } |
| 131 | } |