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