blob: 8e92a862be12fb3af5d50aae114b7d44d9258235 [file] [log] [blame]
Alexandre Lision2e52d392013-11-06 15:14:31 -05001/*
Alexandre Lisionc1024c02014-01-06 11:12:53 -05002 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
Alexandre Lision2e52d392013-11-06 15:14:31 -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
32package org.sflphone.fragments;
33
Alexandre Lisionddbb46f2013-12-12 12:18:58 -050034import java.io.InvalidObjectException;
Alexandre Lision2e52d392013-11-06 15:14:31 -050035import java.util.ArrayList;
Alexandre Lisionddbb46f2013-12-12 12:18:58 -050036import java.util.HashMap;
Alexandre Lision2e52d392013-11-06 15:14:31 -050037import java.util.NavigableMap;
38
Alexandre Lisiondede80e2014-01-29 09:51:07 -050039import android.util.Log;
40import android.widget.*;
Alexandre Lision2e52d392013-11-06 15:14:31 -050041import org.sflphone.R;
42import org.sflphone.adapters.ContactPictureTask;
Alexandre Lisionb4e60612014-01-14 17:47:23 -050043import org.sflphone.history.HistoryCall;
Alexandre Lisionddbb46f2013-12-12 12:18:58 -050044import org.sflphone.model.Account;
Alexandre Lisionb4e60612014-01-14 17:47:23 -050045import org.sflphone.history.HistoryEntry;
Alexandre Lisionddbb46f2013-12-12 12:18:58 -050046import org.sflphone.model.SipCall;
Alexandre Lision2e52d392013-11-06 15:14:31 -050047import org.sflphone.service.ISipService;
Alexandre Lision2e52d392013-11-06 15:14:31 -050048
49import android.app.Activity;
50import android.app.Fragment;
51import android.content.Context;
52import android.os.Bundle;
53import android.os.RemoteException;
54import android.view.LayoutInflater;
55import android.view.View;
56import android.view.View.MeasureSpec;
57import android.view.View.OnClickListener;
58import android.view.ViewGroup;
Alexandre Lisiondede80e2014-01-29 09:51:07 -050059import org.sflphone.views.paralloid.ParallaxController;
60import org.sflphone.views.paralloid.Parallaxor;
61import org.sflphone.views.paralloidviews.ParallaxListView;
62import org.sflphone.views.paralloidviews.ParallaxScrollView;
Alexandre Lision2e52d392013-11-06 15:14:31 -050063
64public class DetailsHistoryEntryFragment extends Fragment {
65
Alexandre Lision2e52d392013-11-06 15:14:31 -050066 DetailHistoryAdapter mAdapter;
67 HistoryEntry toDisplay;
Alexandre Lisiona8b78722013-12-13 10:18:33 -050068 @SuppressWarnings("unused")
Alexandre Lision2e52d392013-11-06 15:14:31 -050069 private static final String TAG = DetailsHistoryEntryFragment.class.getSimpleName();
70 ContactPictureTask tasker;
71
Alexandre Lision2e52d392013-11-06 15:14:31 -050072 private ListView lvMain;
Alexandre Lisiondede80e2014-01-29 09:51:07 -050073 private LinearLayout llMain;
Alexandre Lision2e52d392013-11-06 15:14:31 -050074 private RelativeLayout iv;
75
76 private Callbacks mCallbacks = sDummyCallbacks;
77
78 private static Callbacks sDummyCallbacks = new Callbacks() {
79
80 @Override
81 public ISipService getService() {
82 return null;
83 }
84
Alexandre Lision6da3bb92013-12-10 17:32:46 -050085 @Override
Alexandre Lisionddbb46f2013-12-12 12:18:58 -050086 public void onCall(SipCall call) {
Alexandre Lision6da3bb92013-12-10 17:32:46 -050087 }
88
Alexandre Lision2e52d392013-11-06 15:14:31 -050089 };
90
91 public interface Callbacks {
92
93 public ISipService getService();
Alexandre Lisiondede80e2014-01-29 09:51:07 -050094
Alexandre Lisionddbb46f2013-12-12 12:18:58 -050095 public void onCall(SipCall call);
Alexandre Lision2e52d392013-11-06 15:14:31 -050096
97 }
98
99 @Override
100 public void onAttach(Activity activity) {
101 super.onAttach(activity);
102
103 if (!(activity instanceof Callbacks)) {
104 throw new IllegalStateException("Activity must implement fragment's callbacks.");
105 }
106
107 mCallbacks = (Callbacks) activity;
108 }
109
110 @Override
111 public void onDetach() {
112 super.onDetach();
113 mCallbacks = sDummyCallbacks;
114 }
115
116 @Override
117 public void onCreate(Bundle savedInstanceState) {
118 super.onCreate(savedInstanceState);
119
120 toDisplay = (HistoryEntry) getArguments().get("entry");
121 mAdapter = new DetailHistoryAdapter(toDisplay.getCalls(), getActivity());
122 }
123
124 @Override
125 public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
126 View inflatedView = inflater.inflate(R.layout.frag_history_detail, parent, false);
127
Alexandre Lision2e52d392013-11-06 15:14:31 -0500128 llMain = (LinearLayout) inflatedView.findViewById(R.id.llMain);
Alexandre Lisiondede80e2014-01-29 09:51:07 -0500129 /*llMainHolder = (LinearLayout) inflatedView.findViewById(R.id.llMainHolder);*/
Alexandre Lision2e52d392013-11-06 15:14:31 -0500130 lvMain = (ListView) inflatedView.findViewById(R.id.lvMain);
131 lvMain.setAdapter(mAdapter);
132 iv = (RelativeLayout) inflatedView.findViewById(R.id.iv);
133
134 ((TextView) iv.findViewById(R.id.history_call_name)).setText(toDisplay.getContact().getmDisplayName());
Alexandre Lisionab0cc9f2013-12-12 11:27:25 -0500135
Alexandre Lisiondede80e2014-01-29 09:51:07 -0500136 tasker = new ContactPictureTask(getActivity(), (ImageView) inflatedView.findViewById(R.id.contact_photo), toDisplay.getContact());
Alexandre Lisionab0cc9f2013-12-12 11:27:25 -0500137 tasker.run();
Alexandre Lisiondede80e2014-01-29 09:51:07 -0500138// ((TextView) iv.findViewById(R.id.history_entry_number)).setText(getString(R.string.detail_hist_call_number, toDisplay.getNumber()));
139 iv.findViewById(R.id.history_call_name).setOnClickListener(new OnClickListener() {
Alexandre Lision6da3bb92013-12-10 17:32:46 -0500140
141 @Override
142 public void onClick(View v) {
Alexandre Lisionddbb46f2013-12-12 12:18:58 -0500143 try {
144 SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
145
146 HashMap<String, String> details = (HashMap<String, String>) mCallbacks.getService().getAccountDetails(toDisplay.getAccountID());
Alexandre Lisiondede80e2014-01-29 09:51:07 -0500147 ArrayList<HashMap<String, String>> creds = (ArrayList<HashMap<String, String>>) mCallbacks.getService().getCredentials(toDisplay.getAccountID());
Alexandre Lisionddbb46f2013-12-12 12:18:58 -0500148
149 callBuilder.startCallCreation().setAccount(new Account(toDisplay.getAccountID(), details, creds))
Alexandre Lision67c70b42014-01-16 13:57:15 -0500150 .setCallType(SipCall.direction.CALL_TYPE_OUTGOING);
Alexandre Lisionddbb46f2013-12-12 12:18:58 -0500151 callBuilder.setContact(toDisplay.getContact());
152
153 mCallbacks.onCall(callBuilder.build());
154
155 } catch (RemoteException e) {
156 // TODO Bloc catch généré automatiquement
157 e.printStackTrace();
158 } catch (InvalidObjectException e) {
159 // TODO Bloc catch généré automatiquement
160 e.printStackTrace();
161 }
Alexandre Lision6da3bb92013-12-10 17:32:46 -0500162 }
163 });
Alexandre Lision2e52d392013-11-06 15:14:31 -0500164 return inflatedView;
165 }
166
167 public void onActivityCreated(Bundle savedInstanceState) {
168 super.onActivityCreated(savedInstanceState);
169
170 }
171
Alexandre Lision2e52d392013-11-06 15:14:31 -0500172 private class DetailHistoryAdapter extends BaseAdapter implements ListAdapter {
173
174 ArrayList<HistoryCall> dataset;
175 Context mContext;
176
177 public DetailHistoryAdapter(NavigableMap<Long, HistoryCall> calls, Context c) {
178 dataset = new ArrayList<HistoryCall>(calls.descendingMap().values());
179 mContext = c;
180 }
181
182 @Override
183 public int getCount() {
184 return dataset.size();
185 }
186
187 @Override
188 public Object getItem(int position) {
189 return dataset.get(position);
190 }
191
192 @Override
193 public long getItemId(int position) {
194 return 0;
195 }
196
197 @Override
198 public View getView(int position, View convertView, ViewGroup parent) {
199 HistoryCallView entryView = null;
200
201 if (convertView == null) {
202 // Get a new instance of the row layout view
203 LayoutInflater inflater = LayoutInflater.from(mContext);
204 convertView = inflater.inflate(R.layout.item_history_call, null);
205
206 // Hold the view objects in an object
207 // so they don't need to be re-fetched
208 entryView = new HistoryCallView();
209 entryView.historyCallState = (TextView) convertView.findViewById(R.id.history_call_state);
210 entryView.formatted_date = (TextView) convertView.findViewById(R.id.history_call_date_formatted);
Alexandre Lision6da3bb92013-12-10 17:32:46 -0500211 entryView.formatted_hour = (TextView) convertView.findViewById(R.id.history_call_hour);
Alexandre Lision2e52d392013-11-06 15:14:31 -0500212 entryView.record = (Button) convertView.findViewById(R.id.history_call_record);
213 entryView.duration = (TextView) convertView.findViewById(R.id.history_call_duration);
214
215 convertView.setTag(entryView);
216 } else {
217 entryView = (HistoryCallView) convertView.getTag();
218 }
219
220 final HistoryCall item = dataset.get(position);
221
Alexandre Lisioncb2345c2013-12-09 15:39:13 -0500222 entryView.historyCallState.setText(item.getDirection());
Alexandre Lision2e52d392013-11-06 15:14:31 -0500223 entryView.formatted_date.setText(item.getDate());
Alexandre Lision2e52d392013-11-06 15:14:31 -0500224 entryView.duration.setText(item.getDurationString());
Alexandre Lision6da3bb92013-12-10 17:32:46 -0500225 entryView.formatted_hour.setText(item.getStartString("h:mm a"));
226 if (item.isIncoming() && item.isMissed())
Alexandre Lisioncb2345c2013-12-09 15:39:13 -0500227 convertView.setBackgroundColor(getResources().getColor(R.color.holo_red_light));
Alexandre Lision2e52d392013-11-06 15:14:31 -0500228
229 if (item.hasRecord()) {
230 entryView.record.setVisibility(View.VISIBLE);
231 entryView.record.setTag(R.id.history_call_record, true);
232 entryView.record.setOnClickListener(new OnClickListener() {
233
234 @Override
235 public void onClick(View v) {
236 try {
237 if ((Boolean) v.getTag(R.id.history_call_record)) {
238 mCallbacks.getService().startRecordedFilePlayback(item.getRecordPath());
239 v.setTag(R.id.replay, false);
240 ((Button) v).setText(getString(R.string.hist_replay_button_stop));
241 } else {
242 mCallbacks.getService().stopRecordedFilePlayback(item.getRecordPath());
243 v.setTag(R.id.history_call_record, true);
244 ((Button) v).setText(getString(R.string.hist_replay_button));
245 }
246 } catch (RemoteException e) {
247 // TODO Auto-generated catch block
248 e.printStackTrace();
249 }
250 }
251 });
252 }
253
254 return convertView;
255 }
256
Alexandre Lisiondede80e2014-01-29 09:51:07 -0500257 /**
258 * ******************
Alexandre Lision2e52d392013-11-06 15:14:31 -0500259 * ViewHolder Pattern
Alexandre Lisiondede80e2014-01-29 09:51:07 -0500260 * *******************
261 */
Alexandre Lision2e52d392013-11-06 15:14:31 -0500262 public class HistoryCallView {
263 protected TextView historyCallState;
264 protected TextView formatted_date;
Alexandre Lision6da3bb92013-12-10 17:32:46 -0500265 protected TextView formatted_hour;
Alexandre Lision2e52d392013-11-06 15:14:31 -0500266 protected Button record;
267 protected TextView duration;
268 }
269
270 }
271
272}