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 | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 50 | import com.savoirfairelinux.sflphone.model.Conference; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 51 | import com.savoirfairelinux.sflphone.model.SipCall; |
| 52 | import com.savoirfairelinux.sflphone.service.ISipService; |
| 53 | |
alision | b176388 | 2013-06-18 17:30:51 -0400 | [diff] [blame] | 54 | public class HomeFragment extends Fragment { |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 55 | private static final String TAG = HomeFragment.class.getSimpleName(); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 56 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 57 | private Callbacks mCallbacks = sDummyCallbacks; |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 58 | Button access_calls; |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 59 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 60 | /** |
| 61 | * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity. |
| 62 | */ |
| 63 | private static Callbacks sDummyCallbacks = new Callbacks() { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 64 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 65 | @Override |
| 66 | public ISipService getService() { |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 67 | Log.i(TAG, "I'm a dummy"); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 68 | return null; |
| 69 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 70 | |
| 71 | @Override |
| 72 | public void resumeCallActivity() { |
| 73 | } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 74 | }; |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 75 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 76 | /** |
| 77 | * The Activity calling this fragment has to implement this interface |
| 78 | * |
| 79 | */ |
| 80 | public interface Callbacks { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 81 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 82 | public ISipService getService(); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 83 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 84 | public void resumeCallActivity(); |
| 85 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 86 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 87 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 88 | @Override |
| 89 | public void onAttach(Activity activity) { |
| 90 | super.onAttach(activity); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 91 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 92 | if (!(activity instanceof Callbacks)) { |
| 93 | throw new IllegalStateException("Activity must implement fragment's callbacks."); |
| 94 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 95 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 96 | mCallbacks = (Callbacks) activity; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 97 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 98 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 99 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 100 | @Override |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 101 | public void onResume() { |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 102 | super.onResume(); |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 103 | if (mCallbacks.getService() != null) { |
| 104 | try { |
| 105 | HashMap<String, SipCall> calls = (HashMap<String, SipCall>) mCallbacks.getService().getCallList(); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 106 | HashMap<String, Conference> confs = (HashMap<String, Conference>) mCallbacks.getService().getConferenceList(); |
| 107 | Log.i(TAG, "Call size " + calls.size()); |
| 108 | access_calls.setText(calls.size() + " on going calls and "+confs.size()+" conferences"); |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 109 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 110 | } catch (RemoteException e) { |
| 111 | Log.e(TAG, e.toString()); |
| 112 | } |
| 113 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 114 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 115 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 116 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 117 | @Override |
| 118 | public void onDetach() { |
| 119 | super.onDetach(); |
| 120 | mCallbacks = sDummyCallbacks; |
| 121 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 122 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 123 | @Override |
| 124 | public void onCreate(Bundle savedInstanceState) { |
| 125 | super.onCreate(savedInstanceState); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 126 | // mAdapter = new CallElementAdapter(getActivity(), new ArrayList<SipCall>()); |
| 127 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 128 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 129 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 130 | @Override |
| 131 | public void onActivityCreated(Bundle savedInstanceState) { |
| 132 | super.onActivityCreated(savedInstanceState); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 133 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 134 | // Give some text to display if there is no data. In a real |
| 135 | // application this would come from a resource. |
| 136 | // setEmptyText("No phone numbers"); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 137 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 138 | // We have a menu item to show in action bar. |
| 139 | setHasOptionsMenu(true); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 140 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 141 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 142 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 143 | @Override |
| 144 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { |
| 145 | inflater.inflate(R.menu.call_element_menu, menu); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 146 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 147 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 148 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 149 | @Override |
| 150 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
| 151 | Log.i(TAG, "onCreateView"); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 152 | View inflatedView = inflater.inflate(R.layout.frag_home, container, false); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 153 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 154 | access_calls = (Button) inflatedView.findViewById(R.id.access_callactivity); |
| 155 | |
| 156 | access_calls.setOnClickListener(new OnClickListener() { |
| 157 | |
| 158 | @Override |
| 159 | public void onClick(View v) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 160 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 161 | try { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 162 | HashMap<String, SipCall> calls = (HashMap<String, SipCall>) mCallbacks.getService().getCallList(); |
| 163 | HashMap<String, Conference> confs = (HashMap<String, Conference>) mCallbacks.getService().getConferenceList(); |
| 164 | if (calls.isEmpty() && confs.isEmpty()) { |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 165 | Toast.makeText(getActivity(), "No calls", Toast.LENGTH_SHORT).show(); |
| 166 | } else { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 167 | |
| 168 | mCallbacks.resumeCallActivity(); |
| 169 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 170 | } |
| 171 | } catch (RemoteException e) { |
| 172 | Log.e(TAG, e.toString()); |
| 173 | } |
| 174 | |
| 175 | } |
| 176 | }); |
alision | 43a9b36 | 2013-05-01 16:30:15 -0400 | [diff] [blame] | 177 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 178 | return inflatedView; |
| 179 | } |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 180 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 181 | } |