Alexandre Lision | 666b377 | 2013-10-28 17:42:48 -0400 | [diff] [blame^] | 1 | package org.sflphone.fragments; |
| 2 | |
| 3 | import org.sflphone.R; |
| 4 | import org.sflphone.adapters.DiscussArrayAdapter; |
| 5 | import org.sflphone.model.Conference; |
| 6 | import org.sflphone.model.SipMessage; |
| 7 | import org.sflphone.service.ISipService; |
| 8 | |
| 9 | import android.app.Activity; |
| 10 | import android.app.Fragment; |
| 11 | import android.content.Intent; |
| 12 | import android.os.Bundle; |
| 13 | import android.view.LayoutInflater; |
| 14 | import android.view.View; |
| 15 | import android.view.ViewGroup; |
| 16 | import android.widget.ListView; |
| 17 | |
| 18 | public class IMFragment extends Fragment { |
| 19 | static final String TAG = CallListFragment.class.getSimpleName(); |
| 20 | |
| 21 | private Callbacks mCallbacks = sDummyCallbacks; |
| 22 | |
| 23 | DiscussArrayAdapter mAdapter; |
| 24 | ListView list; |
| 25 | |
| 26 | public static final int REQUEST_TRANSFER = 10; |
| 27 | public static final int REQUEST_CONF = 20; |
| 28 | |
| 29 | @Override |
| 30 | public void onCreate(Bundle savedBundle) { |
| 31 | super.onCreate(savedBundle); |
| 32 | |
| 33 | mAdapter = new DiscussArrayAdapter(getActivity()); |
| 34 | |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity. |
| 39 | */ |
| 40 | private static Callbacks sDummyCallbacks = new Callbacks() { |
| 41 | |
| 42 | @Override |
| 43 | public ISipService getService() { |
| 44 | return null; |
| 45 | } |
| 46 | |
| 47 | }; |
| 48 | |
| 49 | /** |
| 50 | * The Activity calling this fragment has to implement this interface |
| 51 | * |
| 52 | */ |
| 53 | public interface Callbacks { |
| 54 | public ISipService getService(); |
| 55 | |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public void onAttach(Activity activity) { |
| 60 | super.onAttach(activity); |
| 61 | |
| 62 | if (!(activity instanceof Callbacks)) { |
| 63 | throw new IllegalStateException("Activity must implement fragment's callbacks."); |
| 64 | } |
| 65 | |
| 66 | mCallbacks = (Callbacks) activity; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public void onDetach() { |
| 71 | super.onDetach(); |
| 72 | mCallbacks = sDummyCallbacks; |
| 73 | } |
| 74 | |
| 75 | |
| 76 | |
| 77 | @Override |
| 78 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
| 79 | ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_imessaging, container, false); |
| 80 | |
| 81 | list = (ListView) rootView.findViewById(R.id.message_list); |
| 82 | list.setAdapter(mAdapter); |
| 83 | |
| 84 | return rootView; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 89 | super.onActivityResult(requestCode, resultCode, data); |
| 90 | } |
| 91 | |
| 92 | public void putMessage(SipMessage msg) { |
| 93 | mAdapter.add(msg); |
| 94 | } |
| 95 | } |