alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 1 | /* |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 2 | * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 3 | * |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 4 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 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 | package com.savoirfairelinux.sflphone.fragments; |
| 32 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 33 | import java.util.HashMap; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 34 | |
| 35 | import android.app.Activity; |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 36 | import android.app.Fragment; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 37 | import android.os.Bundle; |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 38 | import android.os.RemoteException; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 39 | import android.util.Log; |
| 40 | import android.view.LayoutInflater; |
alision | d8c8388 | 2013-05-17 17:00:42 -0400 | [diff] [blame] | 41 | import android.view.Menu; |
| 42 | import android.view.MenuInflater; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 43 | import android.view.View; |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 44 | import android.view.View.OnClickListener; |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 45 | import android.view.ViewGroup; |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 46 | import android.widget.Button; |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 47 | import android.widget.Toast; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 48 | |
| 49 | import com.savoirfairelinux.sflphone.R; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 50 | import com.savoirfairelinux.sflphone.model.SipCall; |
| 51 | import com.savoirfairelinux.sflphone.service.ISipService; |
| 52 | |
| 53 | /** |
| 54 | * Main list of Call Elements. We don't manage contacts ourself so they are |
| 55 | */ |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 56 | public class HomeFragment extends Fragment { |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 57 | private static final String TAG = HomeFragment.class.getSimpleName(); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame^] | 58 | |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 59 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 60 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 61 | private Callbacks mCallbacks = sDummyCallbacks; |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 62 | Button access_calls; |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 63 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 64 | /** |
| 65 | * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity. |
| 66 | */ |
| 67 | private static Callbacks sDummyCallbacks = new Callbacks() { |
| 68 | @Override |
| 69 | public void onCallSelected(SipCall c) { |
| 70 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 71 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 72 | @Override |
| 73 | public ISipService getService() { |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 74 | Log.i(TAG, "I'm a dummy"); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 75 | return null; |
| 76 | } |
| 77 | }; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 78 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 79 | /** |
| 80 | * The Activity calling this fragment has to implement this interface |
| 81 | * |
| 82 | */ |
| 83 | public interface Callbacks { |
| 84 | public void onCallSelected(SipCall c); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 85 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 86 | public ISipService getService(); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 87 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 88 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 89 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 90 | @Override |
| 91 | public void onAttach(Activity activity) { |
| 92 | super.onAttach(activity); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 93 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 94 | if (!(activity instanceof Callbacks)) { |
| 95 | throw new IllegalStateException("Activity must implement fragment's callbacks."); |
| 96 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 97 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 98 | mCallbacks = (Callbacks) activity; |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 99 | |
| 100 | |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public void onResume(){ |
| 105 | super.onResume(); |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 106 | if (mCallbacks.getService() != null) { |
| 107 | try { |
| 108 | HashMap<String, SipCall> calls = (HashMap<String, SipCall>) mCallbacks.getService().getCallList(); |
| 109 | Log.i(TAG, "Call size "+calls.size()); |
| 110 | access_calls.setText(calls.size()+" on going calls"); |
| 111 | |
| 112 | |
| 113 | } catch (RemoteException e) { |
| 114 | Log.e(TAG, e.toString()); |
| 115 | } |
| 116 | } |
| 117 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 118 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 119 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 120 | @Override |
| 121 | public void onDetach() { |
| 122 | super.onDetach(); |
| 123 | mCallbacks = sDummyCallbacks; |
| 124 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 125 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 126 | /** |
| 127 | * Runnable that fill information in a contact card asynchroniously. |
| 128 | */ |
| 129 | /* |
| 130 | * public static class InfosLoader implements Runnable { private View view; private long cid; private ContentResolver cr; |
| 131 | * |
| 132 | * public InfosLoader(Context context, View element, long contact_id) { cid = contact_id; cr = context.getContentResolver(); view = element; } |
| 133 | * |
| 134 | * public static Bitmap loadContactPhoto(ContentResolver cr, long id) { Uri uri = |
| 135 | * ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, id); InputStream input = |
| 136 | * ContactsContract.Contacts.openContactPhotoInputStream(cr, uri); if (input == null) { return null; } return BitmapFactory.decodeStream(input); } |
| 137 | * |
| 138 | * @Override public void run() { final Bitmap photo_bmp = loadContactPhoto(cr, cid); |
| 139 | * |
| 140 | * Cursor phones = cr.query(CommonDataKinds.Phone.CONTENT_URI, CONTACTS_PHONES_PROJECTION, CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] |
| 141 | * { Long.toString(cid) }, null); |
| 142 | * |
| 143 | * final List<String> numbers = new ArrayList<String>(); while (phones.moveToNext()) { String number = |
| 144 | * phones.getString(phones.getColumnIndex(CommonDataKinds.Phone.NUMBER)); // int type = |
| 145 | * phones.getInt(phones.getColumnIndex(CommonDataKinds.Phone.TYPE)); numbers.add(number); } phones.close(); // TODO: same for SIP adresses. |
| 146 | * |
| 147 | * final Bitmap bmp = photo_bmp; view.post(new Runnable() { |
| 148 | * |
| 149 | * @Override public void run() { } }); } } |
| 150 | */ |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 151 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 152 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 153 | // public void removeCall(SipCall c) { |
| 154 | // Log.i(TAG, "Removing call " + c.mCallInfo.mDisplayName); |
| 155 | // mAdapter.remove(c); |
| 156 | // } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 157 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 158 | @Override |
| 159 | public void onCreate(Bundle savedInstanceState) { |
| 160 | super.onCreate(savedInstanceState); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame^] | 161 | // mAdapter = new CallElementAdapter(getActivity(), new ArrayList<SipCall>()); |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 162 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 163 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 164 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 165 | @Override |
| 166 | public void onActivityCreated(Bundle savedInstanceState) { |
| 167 | super.onActivityCreated(savedInstanceState); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 168 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 169 | // Give some text to display if there is no data. In a real |
| 170 | // application this would come from a resource. |
| 171 | // setEmptyText("No phone numbers"); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 172 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 173 | // We have a menu item to show in action bar. |
| 174 | setHasOptionsMenu(true); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 175 | |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 176 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 177 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 178 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 179 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 180 | @Override |
| 181 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { |
| 182 | inflater.inflate(R.menu.call_element_menu, menu); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 183 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 184 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 185 | |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 186 | // private static final int REQUEST_CODE_PREFERENCES = 1; |
| 187 | // |
| 188 | // @Override |
| 189 | // public boolean onOptionsItemSelected(MenuItem item) { |
| 190 | // Log.i(TAG, "onOptionsItemSelected " + item.getItemId()); |
| 191 | // switch (item.getItemId()) { |
| 192 | // case R.id.menu_settings: |
| 193 | // Intent launchPreferencesIntent = new Intent().setClass(getActivity(), SFLPhonePreferenceActivity.class); |
| 194 | // startActivityForResult(launchPreferencesIntent, SFLPhoneHomeActivity.REQUEST_CODE_PREFERENCES); |
| 195 | // break; |
| 196 | // } |
| 197 | // |
| 198 | // return super.onOptionsItemSelected(item); |
| 199 | // } |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 200 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame^] | 201 | |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 202 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 203 | @Override |
| 204 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
| 205 | Log.i(TAG, "onCreateView"); |
| 206 | View inflatedView = inflater.inflate(R.layout.frag_call_element, container, false); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 207 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 208 | access_calls = (Button) inflatedView.findViewById(R.id.access_callactivity); |
| 209 | |
| 210 | access_calls.setOnClickListener(new OnClickListener() { |
| 211 | |
| 212 | @Override |
| 213 | public void onClick(View v) { |
| 214 | HashMap<String, SipCall> calls; |
| 215 | try { |
| 216 | calls = (HashMap<String, SipCall>) mCallbacks.getService().getCallList(); |
| 217 | if (calls.size() == 0) { |
| 218 | Toast.makeText(getActivity(), "No calls", Toast.LENGTH_SHORT).show(); |
| 219 | } else { |
| 220 | mCallbacks.onCallSelected((SipCall) calls.values().toArray()[0]); |
| 221 | } |
| 222 | } catch (RemoteException e) { |
| 223 | Log.e(TAG, e.toString()); |
| 224 | } |
| 225 | |
| 226 | } |
| 227 | }); |
| 228 | |
| 229 | |
| 230 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 231 | // ((Button) inflatedView.findViewById(R.id.button_attended)).setOnClickListener(new OnClickListener() { |
| 232 | // |
| 233 | // @Override |
| 234 | // public void onClick(View v) { |
| 235 | // if (mAdapter.getCount() == 2) { |
| 236 | // try { |
| 237 | // service.attendedTransfer(mAdapter.getItem(0).getCallId(), mAdapter.getItem(1).getCallId()); |
| 238 | // mAdapter.clear(); |
| 239 | // } catch (RemoteException e) { |
| 240 | // Log.e(TAG, e.toString()); |
| 241 | // } |
| 242 | // } else { |
| 243 | // Toast.makeText(getActivity(), "You need two calls one on Hold the other current to bind them", Toast.LENGTH_LONG).show(); |
| 244 | // } |
| 245 | // |
| 246 | // } |
| 247 | // }); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 248 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 249 | // ((Button) inflatedView.findViewById(R.id.button_conf)).setOnClickListener(new OnClickListener() { |
| 250 | // |
| 251 | // @Override |
| 252 | // public void onClick(View v) { |
| 253 | // if (mAdapter.getCount() == 2) { |
| 254 | // try { |
| 255 | // service.joinParticipant(mAdapter.getItem(0).getCallId(), mAdapter.getItem(1).getCallId()); |
| 256 | // } catch (RemoteException e) { |
| 257 | // Log.e(TAG, e.toString()); |
| 258 | // } |
| 259 | // } else { |
| 260 | // Toast.makeText(getActivity(), "You need two calls one on Hold the other current to create a conference", Toast.LENGTH_LONG) |
| 261 | // .show(); |
| 262 | // } |
| 263 | // } |
| 264 | // }); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 265 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 266 | // ((ToggleButton) inflatedView.findViewById(R.id.switch_hold)).setOnCheckedChangeListener(new OnCheckedChangeListener() { |
| 267 | // |
| 268 | // @Override |
| 269 | // public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
| 270 | // try { |
| 271 | // ArrayList<String> confList = (ArrayList<String>) service.getConferenceList(); |
| 272 | // if (!confList.isEmpty()) { |
| 273 | // if (isChecked) { |
| 274 | // service.holdConference(confList.get(0)); |
| 275 | // } else { |
| 276 | // service.unholdConference(confList.get(0)); |
| 277 | // } |
| 278 | // } |
| 279 | // } catch (RemoteException e) { |
| 280 | // Log.e(TAG, e.toString()); |
| 281 | // } |
| 282 | // |
| 283 | // } |
| 284 | // }); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 285 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 286 | return inflatedView; |
| 287 | } |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 288 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 289 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 290 | } |