blob: b1d175c9508c3f02eed0cbdb06346901c9847960 [file] [log] [blame]
alisionfde875f2013-05-28 17:01:54 -04001/*
2 * Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
3 *
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
32package com.savoirfairelinux.sflphone.fragments;
33
34import java.util.ArrayList;
35import java.util.HashMap;
36
37import android.app.Activity;
38import android.app.Fragment;
alisionfde875f2013-05-28 17:01:54 -040039import android.os.Bundle;
40import android.os.RemoteException;
41import android.util.Log;
42import android.view.LayoutInflater;
43import android.view.View;
44import android.view.ViewGroup;
alision85992112013-05-29 12:18:08 -040045import android.widget.AdapterView;
46import android.widget.AdapterView.OnItemClickListener;
47import android.widget.ListView;
alision85704182013-05-29 15:23:03 -040048import android.widget.Toast;
alisionfde875f2013-05-28 17:01:54 -040049
50import com.savoirfairelinux.sflphone.R;
51import com.savoirfairelinux.sflphone.adapters.CallListAdapter;
52import com.savoirfairelinux.sflphone.model.SipCall;
53import com.savoirfairelinux.sflphone.service.ISipService;
54
55public class CallListFragment extends Fragment {
56 static final String TAG = "CallFragment";
57
58 private Callbacks mCallbacks = sDummyCallbacks;
59
60 CallListAdapter mAdapter;
61
alisionfde875f2013-05-28 17:01:54 -040062
63 @Override
64 public void onCreate(Bundle savedBundle) {
65 super.onCreate(savedBundle);
66
alision85992112013-05-29 12:18:08 -040067 mAdapter = new CallListAdapter(getActivity(), new ArrayList<SipCall>());
alisionfde875f2013-05-28 17:01:54 -040068
69 }
70
71 /**
72 * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity.
73 */
74 private static Callbacks sDummyCallbacks = new Callbacks() {
75
76 @Override
77 public ISipService getService() {
alisionfde875f2013-05-28 17:01:54 -040078 return null;
79 }
alision85992112013-05-29 12:18:08 -040080
81 @Override
82 public void onCallSelected(SipCall call) {
83 }
alisionfde875f2013-05-28 17:01:54 -040084 };
85
86 /**
87 * The Activity calling this fragment has to implement this interface
88 *
89 */
90 public interface Callbacks {
91 public ISipService getService();
alision85992112013-05-29 12:18:08 -040092 public void onCallSelected(SipCall call);
alisionfde875f2013-05-28 17:01:54 -040093
94 }
95
96 @Override
97 public void onAttach(Activity activity) {
98 super.onAttach(activity);
99
100 if (!(activity instanceof Callbacks)) {
101 throw new IllegalStateException("Activity must implement fragment's callbacks.");
102 }
103
104 mCallbacks = (Callbacks) activity;
105 }
106
107 @Override
108 public void onDetach() {
109 super.onDetach();
110 mCallbacks = sDummyCallbacks;
111 }
112
113 @Override
114 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
115 ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_call_list, container, false);
116
alision85992112013-05-29 12:18:08 -0400117 ListView list = (ListView) rootView.findViewById(R.id.call_list);
118 list.setDividerHeight(2);
119// expandbleLis.setGroupIndicator(null);
120 list.setClickable(true);
alisionfde875f2013-05-28 17:01:54 -0400121
alision85992112013-05-29 12:18:08 -0400122 list.setAdapter(mAdapter);
123
124 list.setOnItemClickListener(itemClickListener);
alisionfde875f2013-05-28 17:01:54 -0400125 return rootView;
126 }
127
128 public void update() {
129 try {
130 HashMap<String, SipCall> list = (HashMap<String, SipCall>) mCallbacks.getService().getCallList();
alision85992112013-05-29 12:18:08 -0400131 mAdapter.update(list);
alisionfde875f2013-05-28 17:01:54 -0400132 } catch (RemoteException e) {
133 Log.e(TAG, e.toString());
134 }
135
136 }
alision85992112013-05-29 12:18:08 -0400137
138 OnItemClickListener itemClickListener = new OnItemClickListener() {
139
140 @Override
141 public void onItemClick(AdapterView<?> arg0, View view, int pos, long arg3) {
alision85704182013-05-29 15:23:03 -0400142 Toast.makeText(getActivity(), "ItemClicked", Toast.LENGTH_SHORT).show();
alision85992112013-05-29 12:18:08 -0400143 mCallbacks.onCallSelected(mAdapter.getItem(pos));
144
145 }
146 };
alisionfde875f2013-05-28 17:01:54 -0400147
148}