blob: 96cb3f894b7f38b9547748aca74c354485f78b8b [file] [log] [blame]
alisionf76de3b2013-04-16 15:35:22 -04001/*
alision2ec64f92013-06-17 17:28:58 -04002 * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
alisionf76de3b2013-04-16 15:35:22 -04003 *
alision2ec64f92013-06-17 17:28:58 -04004 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
alisionf76de3b2013-04-16 15:35:22 -04005 *
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 */
31package com.savoirfairelinux.sflphone.fragments;
32
alision2cb99562013-05-30 17:02:20 -040033import java.util.HashMap;
alisionf76de3b2013-04-16 15:35:22 -040034
35import android.app.Activity;
alisionb1763882013-06-18 17:30:51 -040036import android.app.Fragment;
alisionf76de3b2013-04-16 15:35:22 -040037import android.os.Bundle;
alision2cb99562013-05-30 17:02:20 -040038import android.os.RemoteException;
alisionf76de3b2013-04-16 15:35:22 -040039import android.util.Log;
40import android.view.LayoutInflater;
alisiond8c83882013-05-17 17:00:42 -040041import android.view.Menu;
42import android.view.MenuInflater;
alisionf76de3b2013-04-16 15:35:22 -040043import android.view.View;
alision2cb99562013-05-30 17:02:20 -040044import android.view.View.OnClickListener;
alision43a9b362013-05-01 16:30:15 -040045import android.view.ViewGroup;
alision43a9b362013-05-01 16:30:15 -040046import android.widget.Button;
alision2cb99562013-05-30 17:02:20 -040047import android.widget.Toast;
alisionf76de3b2013-04-16 15:35:22 -040048
49import com.savoirfairelinux.sflphone.R;
alisiondf1dac92013-06-27 17:35:53 -040050import com.savoirfairelinux.sflphone.model.Conference;
alisionf76de3b2013-04-16 15:35:22 -040051import com.savoirfairelinux.sflphone.model.SipCall;
52import com.savoirfairelinux.sflphone.service.ISipService;
53
alisionb1763882013-06-18 17:30:51 -040054public class HomeFragment extends Fragment {
alision55c36cb2013-06-14 14:57:38 -040055 private static final String TAG = HomeFragment.class.getSimpleName();
alision907bde72013-06-20 14:40:37 -040056
alision9f7a6ec2013-05-24 16:26:26 -040057 private Callbacks mCallbacks = sDummyCallbacks;
alision2cb99562013-05-30 17:02:20 -040058 Button access_calls;
alision43a9b362013-05-01 16:30:15 -040059
alision9f7a6ec2013-05-24 16:26:26 -040060 /**
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() {
alision371b77e2013-04-23 14:51:26 -040064
alision9f7a6ec2013-05-24 16:26:26 -040065 @Override
66 public ISipService getService() {
alision2cb99562013-05-30 17:02:20 -040067 Log.i(TAG, "I'm a dummy");
alision9f7a6ec2013-05-24 16:26:26 -040068 return null;
69 }
alisiondf1dac92013-06-27 17:35:53 -040070
71 @Override
72 public void resumeCallActivity() {
73 }
alision9f7a6ec2013-05-24 16:26:26 -040074 };
alision371b77e2013-04-23 14:51:26 -040075
alision9f7a6ec2013-05-24 16:26:26 -040076 /**
77 * The Activity calling this fragment has to implement this interface
78 *
79 */
80 public interface Callbacks {
alision371b77e2013-04-23 14:51:26 -040081
alision9f7a6ec2013-05-24 16:26:26 -040082 public ISipService getService();
alision43a9b362013-05-01 16:30:15 -040083
alisiondf1dac92013-06-27 17:35:53 -040084 public void resumeCallActivity();
85
alision9f7a6ec2013-05-24 16:26:26 -040086 }
alisionf76de3b2013-04-16 15:35:22 -040087
alision9f7a6ec2013-05-24 16:26:26 -040088 @Override
89 public void onAttach(Activity activity) {
90 super.onAttach(activity);
alisionf76de3b2013-04-16 15:35:22 -040091
alision9f7a6ec2013-05-24 16:26:26 -040092 if (!(activity instanceof Callbacks)) {
93 throw new IllegalStateException("Activity must implement fragment's callbacks.");
94 }
alisionf76de3b2013-04-16 15:35:22 -040095
alision9f7a6ec2013-05-24 16:26:26 -040096 mCallbacks = (Callbacks) activity;
alisiondf1dac92013-06-27 17:35:53 -040097
alision2cb99562013-05-30 17:02:20 -040098 }
alisiondf1dac92013-06-27 17:35:53 -040099
alision2cb99562013-05-30 17:02:20 -0400100 @Override
alisiondf1dac92013-06-27 17:35:53 -0400101 public void onResume() {
alision2cb99562013-05-30 17:02:20 -0400102 super.onResume();
alision2cb99562013-05-30 17:02:20 -0400103 if (mCallbacks.getService() != null) {
104 try {
105 HashMap<String, SipCall> calls = (HashMap<String, SipCall>) mCallbacks.getService().getCallList();
alisiondf1dac92013-06-27 17:35:53 -0400106 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");
alision2cb99562013-05-30 17:02:20 -0400109
alision2cb99562013-05-30 17:02:20 -0400110 } catch (RemoteException e) {
111 Log.e(TAG, e.toString());
112 }
113 }
alisiondf1dac92013-06-27 17:35:53 -0400114
alision9f7a6ec2013-05-24 16:26:26 -0400115 }
alisionf76de3b2013-04-16 15:35:22 -0400116
alision9f7a6ec2013-05-24 16:26:26 -0400117 @Override
118 public void onDetach() {
119 super.onDetach();
120 mCallbacks = sDummyCallbacks;
121 }
alisionf76de3b2013-04-16 15:35:22 -0400122
alision9f7a6ec2013-05-24 16:26:26 -0400123 @Override
124 public void onCreate(Bundle savedInstanceState) {
125 super.onCreate(savedInstanceState);
alisiondf1dac92013-06-27 17:35:53 -0400126 // mAdapter = new CallElementAdapter(getActivity(), new ArrayList<SipCall>());
127
alision9f7a6ec2013-05-24 16:26:26 -0400128 }
alisionf76de3b2013-04-16 15:35:22 -0400129
alision9f7a6ec2013-05-24 16:26:26 -0400130 @Override
131 public void onActivityCreated(Bundle savedInstanceState) {
132 super.onActivityCreated(savedInstanceState);
alisionf76de3b2013-04-16 15:35:22 -0400133
alision9f7a6ec2013-05-24 16:26:26 -0400134 // 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");
alisionf76de3b2013-04-16 15:35:22 -0400137
alision9f7a6ec2013-05-24 16:26:26 -0400138 // We have a menu item to show in action bar.
139 setHasOptionsMenu(true);
alisionf76de3b2013-04-16 15:35:22 -0400140
alision9f7a6ec2013-05-24 16:26:26 -0400141 }
alision371b77e2013-04-23 14:51:26 -0400142
alision9f7a6ec2013-05-24 16:26:26 -0400143 @Override
144 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
145 inflater.inflate(R.menu.call_element_menu, menu);
alisionf76de3b2013-04-16 15:35:22 -0400146
alision9f7a6ec2013-05-24 16:26:26 -0400147 }
alisionf76de3b2013-04-16 15:35:22 -0400148
alision9f7a6ec2013-05-24 16:26:26 -0400149 @Override
150 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
151 Log.i(TAG, "onCreateView");
alision465ceba2013-07-04 09:24:30 -0400152 View inflatedView = inflater.inflate(R.layout.frag_home, container, false);
alision43a9b362013-05-01 16:30:15 -0400153
alision2cb99562013-05-30 17:02:20 -0400154 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) {
alisiondf1dac92013-06-27 17:35:53 -0400160
alision2cb99562013-05-30 17:02:20 -0400161 try {
alisiondf1dac92013-06-27 17:35:53 -0400162 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()) {
alision2cb99562013-05-30 17:02:20 -0400165 Toast.makeText(getActivity(), "No calls", Toast.LENGTH_SHORT).show();
166 } else {
alisiondf1dac92013-06-27 17:35:53 -0400167
168 mCallbacks.resumeCallActivity();
169
alision2cb99562013-05-30 17:02:20 -0400170 }
171 } catch (RemoteException e) {
172 Log.e(TAG, e.toString());
173 }
174
175 }
176 });
alision43a9b362013-05-01 16:30:15 -0400177
alision9f7a6ec2013-05-24 16:26:26 -0400178 return inflatedView;
179 }
alisione2a38e12013-04-25 14:20:20 -0400180
alisionf76de3b2013-04-16 15:35:22 -0400181}