Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 1 | /* |
Alexandre Lision | c1024c0 | 2014-01-06 11:12:53 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 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 | |
| 32 | package org.sflphone.fragments; |
| 33 | |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 34 | |
| 35 | import android.app.Activity; |
| 36 | import android.app.Fragment; |
| 37 | import android.content.Context; |
| 38 | import android.os.Bundle; |
| 39 | import android.os.RemoteException; |
| 40 | import android.view.LayoutInflater; |
| 41 | import android.view.View; |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 42 | import android.view.View.OnClickListener; |
| 43 | import android.view.ViewGroup; |
Alexandre Lision | 64efcc9 | 2014-01-29 11:25:07 -0500 | [diff] [blame^] | 44 | import android.widget.*; |
| 45 | import org.sflphone.R; |
| 46 | import org.sflphone.adapters.ContactPictureTask; |
| 47 | import org.sflphone.history.HistoryCall; |
| 48 | import org.sflphone.history.HistoryEntry; |
| 49 | import org.sflphone.model.Account; |
| 50 | import org.sflphone.model.SipCall; |
| 51 | import org.sflphone.service.ISipService; |
| 52 | |
| 53 | import java.io.InvalidObjectException; |
| 54 | import java.util.ArrayList; |
| 55 | import java.util.HashMap; |
| 56 | import java.util.NavigableMap; |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 57 | |
| 58 | public class DetailsHistoryEntryFragment extends Fragment { |
| 59 | |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 60 | DetailHistoryAdapter mAdapter; |
| 61 | HistoryEntry toDisplay; |
Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 62 | @SuppressWarnings("unused") |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 63 | private static final String TAG = DetailsHistoryEntryFragment.class.getSimpleName(); |
| 64 | ContactPictureTask tasker; |
| 65 | |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 66 | private ListView lvMain; |
Alexandre Lision | dede80e | 2014-01-29 09:51:07 -0500 | [diff] [blame] | 67 | private LinearLayout llMain; |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 68 | private RelativeLayout iv; |
| 69 | |
| 70 | private Callbacks mCallbacks = sDummyCallbacks; |
| 71 | |
| 72 | private static Callbacks sDummyCallbacks = new Callbacks() { |
| 73 | |
| 74 | @Override |
| 75 | public ISipService getService() { |
| 76 | return null; |
| 77 | } |
| 78 | |
Alexandre Lision | 6da3bb9 | 2013-12-10 17:32:46 -0500 | [diff] [blame] | 79 | @Override |
Alexandre Lision | ddbb46f | 2013-12-12 12:18:58 -0500 | [diff] [blame] | 80 | public void onCall(SipCall call) { |
Alexandre Lision | 6da3bb9 | 2013-12-10 17:32:46 -0500 | [diff] [blame] | 81 | } |
| 82 | |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | public interface Callbacks { |
| 86 | |
| 87 | public ISipService getService(); |
Alexandre Lision | dede80e | 2014-01-29 09:51:07 -0500 | [diff] [blame] | 88 | |
Alexandre Lision | ddbb46f | 2013-12-12 12:18:58 -0500 | [diff] [blame] | 89 | public void onCall(SipCall call); |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 90 | |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public void onAttach(Activity activity) { |
| 95 | super.onAttach(activity); |
| 96 | |
| 97 | if (!(activity instanceof Callbacks)) { |
| 98 | throw new IllegalStateException("Activity must implement fragment's callbacks."); |
| 99 | } |
| 100 | |
| 101 | mCallbacks = (Callbacks) activity; |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public void onDetach() { |
| 106 | super.onDetach(); |
| 107 | mCallbacks = sDummyCallbacks; |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public void onCreate(Bundle savedInstanceState) { |
| 112 | super.onCreate(savedInstanceState); |
| 113 | |
| 114 | toDisplay = (HistoryEntry) getArguments().get("entry"); |
| 115 | mAdapter = new DetailHistoryAdapter(toDisplay.getCalls(), getActivity()); |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) { |
| 120 | View inflatedView = inflater.inflate(R.layout.frag_history_detail, parent, false); |
| 121 | |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 122 | llMain = (LinearLayout) inflatedView.findViewById(R.id.llMain); |
Alexandre Lision | dede80e | 2014-01-29 09:51:07 -0500 | [diff] [blame] | 123 | /*llMainHolder = (LinearLayout) inflatedView.findViewById(R.id.llMainHolder);*/ |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 124 | lvMain = (ListView) inflatedView.findViewById(R.id.lvMain); |
| 125 | lvMain.setAdapter(mAdapter); |
| 126 | iv = (RelativeLayout) inflatedView.findViewById(R.id.iv); |
| 127 | |
| 128 | ((TextView) iv.findViewById(R.id.history_call_name)).setText(toDisplay.getContact().getmDisplayName()); |
Alexandre Lision | ab0cc9f | 2013-12-12 11:27:25 -0500 | [diff] [blame] | 129 | |
Alexandre Lision | dede80e | 2014-01-29 09:51:07 -0500 | [diff] [blame] | 130 | tasker = new ContactPictureTask(getActivity(), (ImageView) inflatedView.findViewById(R.id.contact_photo), toDisplay.getContact()); |
Alexandre Lision | ab0cc9f | 2013-12-12 11:27:25 -0500 | [diff] [blame] | 131 | tasker.run(); |
Alexandre Lision | dede80e | 2014-01-29 09:51:07 -0500 | [diff] [blame] | 132 | // ((TextView) iv.findViewById(R.id.history_entry_number)).setText(getString(R.string.detail_hist_call_number, toDisplay.getNumber())); |
| 133 | iv.findViewById(R.id.history_call_name).setOnClickListener(new OnClickListener() { |
Alexandre Lision | 6da3bb9 | 2013-12-10 17:32:46 -0500 | [diff] [blame] | 134 | |
| 135 | @Override |
| 136 | public void onClick(View v) { |
Alexandre Lision | ddbb46f | 2013-12-12 12:18:58 -0500 | [diff] [blame] | 137 | try { |
| 138 | SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance(); |
| 139 | |
| 140 | HashMap<String, String> details = (HashMap<String, String>) mCallbacks.getService().getAccountDetails(toDisplay.getAccountID()); |
Alexandre Lision | dede80e | 2014-01-29 09:51:07 -0500 | [diff] [blame] | 141 | ArrayList<HashMap<String, String>> creds = (ArrayList<HashMap<String, String>>) mCallbacks.getService().getCredentials(toDisplay.getAccountID()); |
Alexandre Lision | ddbb46f | 2013-12-12 12:18:58 -0500 | [diff] [blame] | 142 | |
| 143 | callBuilder.startCallCreation().setAccount(new Account(toDisplay.getAccountID(), details, creds)) |
Alexandre Lision | 67c70b4 | 2014-01-16 13:57:15 -0500 | [diff] [blame] | 144 | .setCallType(SipCall.direction.CALL_TYPE_OUTGOING); |
Alexandre Lision | ddbb46f | 2013-12-12 12:18:58 -0500 | [diff] [blame] | 145 | callBuilder.setContact(toDisplay.getContact()); |
| 146 | |
| 147 | mCallbacks.onCall(callBuilder.build()); |
| 148 | |
| 149 | } catch (RemoteException e) { |
| 150 | // TODO Bloc catch généré automatiquement |
| 151 | e.printStackTrace(); |
| 152 | } catch (InvalidObjectException e) { |
| 153 | // TODO Bloc catch généré automatiquement |
| 154 | e.printStackTrace(); |
| 155 | } |
Alexandre Lision | 6da3bb9 | 2013-12-10 17:32:46 -0500 | [diff] [blame] | 156 | } |
| 157 | }); |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 158 | return inflatedView; |
| 159 | } |
| 160 | |
| 161 | public void onActivityCreated(Bundle savedInstanceState) { |
| 162 | super.onActivityCreated(savedInstanceState); |
| 163 | |
| 164 | } |
| 165 | |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 166 | private class DetailHistoryAdapter extends BaseAdapter implements ListAdapter { |
| 167 | |
| 168 | ArrayList<HistoryCall> dataset; |
| 169 | Context mContext; |
| 170 | |
| 171 | public DetailHistoryAdapter(NavigableMap<Long, HistoryCall> calls, Context c) { |
| 172 | dataset = new ArrayList<HistoryCall>(calls.descendingMap().values()); |
| 173 | mContext = c; |
| 174 | } |
| 175 | |
| 176 | @Override |
| 177 | public int getCount() { |
| 178 | return dataset.size(); |
| 179 | } |
| 180 | |
| 181 | @Override |
| 182 | public Object getItem(int position) { |
| 183 | return dataset.get(position); |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public long getItemId(int position) { |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | @Override |
| 192 | public View getView(int position, View convertView, ViewGroup parent) { |
| 193 | HistoryCallView entryView = null; |
| 194 | |
| 195 | if (convertView == null) { |
| 196 | // Get a new instance of the row layout view |
| 197 | LayoutInflater inflater = LayoutInflater.from(mContext); |
| 198 | convertView = inflater.inflate(R.layout.item_history_call, null); |
| 199 | |
| 200 | // Hold the view objects in an object |
| 201 | // so they don't need to be re-fetched |
| 202 | entryView = new HistoryCallView(); |
| 203 | entryView.historyCallState = (TextView) convertView.findViewById(R.id.history_call_state); |
| 204 | entryView.formatted_date = (TextView) convertView.findViewById(R.id.history_call_date_formatted); |
Alexandre Lision | 6da3bb9 | 2013-12-10 17:32:46 -0500 | [diff] [blame] | 205 | entryView.formatted_hour = (TextView) convertView.findViewById(R.id.history_call_hour); |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 206 | entryView.record = (Button) convertView.findViewById(R.id.history_call_record); |
| 207 | entryView.duration = (TextView) convertView.findViewById(R.id.history_call_duration); |
| 208 | |
| 209 | convertView.setTag(entryView); |
| 210 | } else { |
| 211 | entryView = (HistoryCallView) convertView.getTag(); |
| 212 | } |
| 213 | |
| 214 | final HistoryCall item = dataset.get(position); |
| 215 | |
Alexandre Lision | cb2345c | 2013-12-09 15:39:13 -0500 | [diff] [blame] | 216 | entryView.historyCallState.setText(item.getDirection()); |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 217 | entryView.formatted_date.setText(item.getDate()); |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 218 | entryView.duration.setText(item.getDurationString()); |
Alexandre Lision | 6da3bb9 | 2013-12-10 17:32:46 -0500 | [diff] [blame] | 219 | entryView.formatted_hour.setText(item.getStartString("h:mm a")); |
| 220 | if (item.isIncoming() && item.isMissed()) |
Alexandre Lision | cb2345c | 2013-12-09 15:39:13 -0500 | [diff] [blame] | 221 | convertView.setBackgroundColor(getResources().getColor(R.color.holo_red_light)); |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 222 | |
| 223 | if (item.hasRecord()) { |
| 224 | entryView.record.setVisibility(View.VISIBLE); |
| 225 | entryView.record.setTag(R.id.history_call_record, true); |
| 226 | entryView.record.setOnClickListener(new OnClickListener() { |
| 227 | |
| 228 | @Override |
| 229 | public void onClick(View v) { |
| 230 | try { |
| 231 | if ((Boolean) v.getTag(R.id.history_call_record)) { |
| 232 | mCallbacks.getService().startRecordedFilePlayback(item.getRecordPath()); |
| 233 | v.setTag(R.id.replay, false); |
| 234 | ((Button) v).setText(getString(R.string.hist_replay_button_stop)); |
| 235 | } else { |
| 236 | mCallbacks.getService().stopRecordedFilePlayback(item.getRecordPath()); |
| 237 | v.setTag(R.id.history_call_record, true); |
| 238 | ((Button) v).setText(getString(R.string.hist_replay_button)); |
| 239 | } |
| 240 | } catch (RemoteException e) { |
| 241 | // TODO Auto-generated catch block |
| 242 | e.printStackTrace(); |
| 243 | } |
| 244 | } |
| 245 | }); |
| 246 | } |
| 247 | |
| 248 | return convertView; |
| 249 | } |
| 250 | |
Alexandre Lision | dede80e | 2014-01-29 09:51:07 -0500 | [diff] [blame] | 251 | /** |
| 252 | * ****************** |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 253 | * ViewHolder Pattern |
Alexandre Lision | dede80e | 2014-01-29 09:51:07 -0500 | [diff] [blame] | 254 | * ******************* |
| 255 | */ |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 256 | public class HistoryCallView { |
| 257 | protected TextView historyCallState; |
| 258 | protected TextView formatted_date; |
Alexandre Lision | 6da3bb9 | 2013-12-10 17:32:46 -0500 | [diff] [blame] | 259 | protected TextView formatted_hour; |
Alexandre Lision | 2e52d39 | 2013-11-06 15:14:31 -0500 | [diff] [blame] | 260 | protected Button record; |
| 261 | protected TextView duration; |
| 262 | } |
| 263 | |
| 264 | } |
| 265 | |
| 266 | } |