alision | fde875f | 2013-05-28 17:01:54 -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 | fde875f | 2013-05-28 17:01:54 -0400 | [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 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 32 | package com.savoirfairelinux.sflphone.fragments; |
| 33 | |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 34 | import java.util.ArrayList; |
| 35 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 36 | import android.app.Activity; |
| 37 | import android.app.Fragment; |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 38 | import android.app.FragmentManager; |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 39 | import android.content.Context; |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 40 | import android.content.Intent; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 41 | import android.graphics.Bitmap; |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 42 | import android.graphics.BitmapFactory; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 43 | import android.graphics.PointF; |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 44 | import android.hardware.Sensor; |
| 45 | import android.hardware.SensorEvent; |
| 46 | import android.hardware.SensorEventListener; |
| 47 | import android.hardware.SensorManager; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 48 | import android.os.Bundle; |
| 49 | import android.os.RemoteException; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 50 | import android.util.Log; |
| 51 | import android.view.LayoutInflater; |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 52 | import android.view.SurfaceHolder; |
| 53 | import android.view.SurfaceHolder.Callback; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 54 | import android.view.View; |
| 55 | import android.view.ViewGroup; |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 56 | import android.view.WindowManager; |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 57 | import android.widget.TextView; |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 58 | import android.widget.Toast; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 59 | |
| 60 | import com.savoirfairelinux.sflphone.R; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 61 | import com.savoirfairelinux.sflphone.model.Attractor; |
| 62 | import com.savoirfairelinux.sflphone.model.Bubble; |
| 63 | import com.savoirfairelinux.sflphone.model.BubbleModel; |
| 64 | import com.savoirfairelinux.sflphone.model.BubblesView; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 65 | import com.savoirfairelinux.sflphone.model.Conference; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 66 | import com.savoirfairelinux.sflphone.model.SipCall; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 67 | import com.savoirfairelinux.sflphone.service.ISipService; |
| 68 | |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 69 | public class CallFragment extends Fragment implements Callback, SensorEventListener { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 70 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 71 | static final String TAG = "CallFragment"; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 72 | |
alision | f57d8a6 | 2013-07-02 09:37:12 -0400 | [diff] [blame] | 73 | float BUBBLE_SIZE = 75; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 74 | static final float ATTRACTOR_SIZE = 40; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 75 | |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 76 | public static final int REQUEST_TRANSFER = 10; |
| 77 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 78 | private Conference conf; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 79 | |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 80 | private TextView callStatusTxt; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 81 | private BubblesView view; |
| 82 | private BubbleModel model; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 83 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 84 | private Callbacks mCallbacks = sDummyCallbacks; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 85 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 86 | private SipCall myself; |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 87 | |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 88 | boolean accepted = false; |
| 89 | |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 90 | private Bitmap hangup_icon, transfer_icon; |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 91 | private Bitmap call_icon; |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 92 | |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 93 | private SensorManager mSensorManager; |
| 94 | |
| 95 | private Sensor mSensor; |
| 96 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 97 | @Override |
| 98 | public void onCreate(Bundle savedBundle) { |
| 99 | super.onCreate(savedBundle); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 100 | Bundle b = getArguments(); |
alision | cd8fb91 | 2013-06-28 14:43:51 -0400 | [diff] [blame] | 101 | conf = new Conference((Conference) b.getParcelable("conference")); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 102 | model = new BubbleModel(getResources().getDisplayMetrics().density); |
alision | 729b0a2 | 2013-07-02 11:57:33 -0400 | [diff] [blame] | 103 | BUBBLE_SIZE = getResources().getDimension(R.dimen.bubble_size); |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 104 | Log.e(TAG, "BUBBLE_SIZE " + BUBBLE_SIZE); |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 105 | mSensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); |
| 106 | mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); |
alision | 729b0a2 | 2013-07-02 11:57:33 -0400 | [diff] [blame] | 107 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 108 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 109 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 110 | /** |
| 111 | * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity. |
| 112 | */ |
| 113 | private static Callbacks sDummyCallbacks = new Callbacks() { |
| 114 | @Override |
| 115 | public void onSendMessage(SipCall call, String msg) { |
| 116 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 117 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 118 | @Override |
| 119 | public void callContact(SipCall call) { |
| 120 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 121 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 122 | @Override |
| 123 | public void onCallAccepted(SipCall call) { |
| 124 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 125 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 126 | @Override |
| 127 | public void onCallRejected(SipCall call) { |
| 128 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 129 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 130 | @Override |
| 131 | public void onCallEnded(SipCall call) { |
| 132 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 133 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 134 | @Override |
| 135 | public void onCallSuspended(SipCall call) { |
| 136 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 137 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 138 | @Override |
| 139 | public void onCallResumed(SipCall call) { |
| 140 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 141 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 142 | @Override |
| 143 | public void onCalltransfered(SipCall call, String to) { |
| 144 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 145 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 146 | @Override |
| 147 | public void onRecordCall(SipCall call) { |
| 148 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 149 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 150 | @Override |
| 151 | public ISipService getService() { |
| 152 | return null; |
| 153 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 154 | |
| 155 | @Override |
| 156 | public void replaceCurrentCallDisplayed() { |
| 157 | } |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 158 | |
| 159 | @Override |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 160 | public void startTimer() { |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 161 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 162 | }; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 163 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 164 | /** |
| 165 | * The Activity calling this fragment has to implement this interface |
| 166 | * |
| 167 | */ |
| 168 | public interface Callbacks { |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 169 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 170 | public ISipService getService(); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 171 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 172 | public void callContact(SipCall call); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 173 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 174 | public void onCallAccepted(SipCall call); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 175 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 176 | public void onCallRejected(SipCall call); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 177 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 178 | public void onCallEnded(SipCall call); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 179 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 180 | public void onCallSuspended(SipCall call); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 181 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 182 | public void onCallResumed(SipCall call); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 183 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 184 | public void onCalltransfered(SipCall call, String to); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 185 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 186 | public void onRecordCall(SipCall call); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 187 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 188 | public void onSendMessage(SipCall call, String msg); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 189 | |
| 190 | public void replaceCurrentCallDisplayed(); |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 191 | |
| 192 | public void startTimer(); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 193 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 194 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 195 | @Override |
| 196 | public void onAttach(Activity activity) { |
| 197 | super.onAttach(activity); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 198 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 199 | if (!(activity instanceof Callbacks)) { |
| 200 | throw new IllegalStateException("Activity must implement fragment's callbacks."); |
| 201 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 202 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 203 | // rootView.requestDisallowInterceptTouchEvent(true); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 204 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 205 | mCallbacks = (Callbacks) activity; |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame] | 206 | myself = SipCall.SipCallBuilder.buildMyselfCall(activity.getContentResolver(), "Me"); |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 207 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 208 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 209 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 210 | @Override |
| 211 | public void onDetach() { |
| 212 | super.onDetach(); |
| 213 | mCallbacks = sDummyCallbacks; |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 214 | mSensorManager.unregisterListener(this); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 215 | // rootView.requestDisallowInterceptTouchEvent(false); |
| 216 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 217 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 218 | @Override |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 219 | public void onStop() { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 220 | super.onStop(); |
| 221 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 222 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 223 | @Override |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 224 | public void onResume() { |
| 225 | super.onResume(); |
| 226 | mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL); |
| 227 | } |
| 228 | |
| 229 | @Override |
| 230 | public void onPause() { |
| 231 | super.onPause(); |
| 232 | mSensorManager.unregisterListener(this); |
| 233 | } |
| 234 | |
| 235 | @Override |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 236 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 237 | super.onActivityResult(requestCode, resultCode, data); |
| 238 | SipCall transfer = null; |
| 239 | if (requestCode == REQUEST_TRANSFER) { |
| 240 | switch (resultCode) { |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 241 | case TransferDFragment.RESULT_TRANSFER_CONF: |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 242 | Conference c = data.getParcelableExtra("target"); |
| 243 | transfer = data.getParcelableExtra("transfer"); |
| 244 | try { |
| 245 | |
| 246 | mCallbacks.getService().attendedTransfer(transfer.getCallId(), c.getParticipants().get(0).getCallId()); |
| 247 | |
| 248 | } catch (RemoteException e) { |
| 249 | // TODO Auto-generated catch block |
| 250 | e.printStackTrace(); |
| 251 | } |
Alexandre Lision | 0edf18c | 2013-09-23 17:35:50 -0400 | [diff] [blame] | 252 | // Toast.makeText(getActivity(), "Transfer complete", Toast.LENGTH_LONG).show(); |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 253 | break; |
| 254 | |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 255 | case TransferDFragment.RESULT_TRANSFER_NUMBER: |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 256 | String to = data.getStringExtra("to_number"); |
| 257 | transfer = data.getParcelableExtra("transfer"); |
| 258 | try { |
Alexandre Lision | 0edf18c | 2013-09-23 17:35:50 -0400 | [diff] [blame] | 259 | // Toast.makeText(getActivity(), "Transferring " + transfer.getContact().getmDisplayName() + " to " + to, Toast.LENGTH_SHORT).show(); |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 260 | mCallbacks.getService().transfer(transfer.getCallId(), to); |
| 261 | mCallbacks.getService().hangUp(transfer.getCallId()); |
| 262 | } catch (RemoteException e) { |
| 263 | // TODO Auto-generated catch block |
| 264 | e.printStackTrace(); |
| 265 | } |
| 266 | break; |
Adrien Béraud | 9751284 | 2013-09-19 13:37:19 +1000 | [diff] [blame] | 267 | case Activity.RESULT_CANCELED: |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 268 | default: |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 269 | model.clear(); |
| 270 | initNormalStateDisplay(); |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 271 | break; |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | @Override |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 277 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
| 278 | ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_call, container, false); |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 279 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 280 | view = (BubblesView) rootView.findViewById(R.id.main_view); |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 281 | view.setFragment(this); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 282 | view.setModel(model); |
| 283 | view.getHolder().addCallback(this); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 284 | |
Alexandre Lision | 3c6b710 | 2013-09-16 16:56:46 -0400 | [diff] [blame] | 285 | callStatusTxt = (TextView) rootView.findViewById(R.id.call_status_txt); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 286 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 287 | hangup_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_hangup); |
| 288 | call_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_call); |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 289 | transfer_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_phones_call_transfer_icon); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 290 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 291 | // Do nothing here, the view is not initialized yet. |
| 292 | return rootView; |
| 293 | } |
alision | 8599211 | 2013-05-29 12:18:08 -0400 | [diff] [blame] | 294 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 295 | private void initNormalStateDisplay() { |
| 296 | Log.i(TAG, "Start normal display"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 297 | |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 298 | mCallbacks.startTimer(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 299 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 300 | getBubbleFor(myself, model.width / 2, model.height / 2); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 301 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 302 | int angle_part = 360 / conf.getParticipants().size(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 303 | double dX = 0; |
| 304 | double dY = 0; |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 305 | int radiusCalls = (int) (model.width / 2 - BUBBLE_SIZE); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 306 | for (int i = 0; i < conf.getParticipants().size(); ++i) { |
| 307 | |
| 308 | if (conf.getParticipants().get(i) == null) { |
| 309 | Log.i(TAG, i + " null "); |
| 310 | continue; |
| 311 | } |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 312 | dX = Math.cos(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
| 313 | dY = Math.sin(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 314 | getBubbleFor(conf.getParticipants().get(i), (int) (model.width / 2 + dX), (int) (model.height / 2 + dY)); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 315 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 316 | |
| 317 | model.clearAttractors(); |
Alexandre Lision | 0edf18c | 2013-09-23 17:35:50 -0400 | [diff] [blame] | 318 | // model.addAttractor(new Attractor(new PointF(model.width * .2f, model.height * 0.9f), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 319 | // @Override |
| 320 | // public boolean onBubbleSucked(Bubble b) { |
| 321 | // Log.w(TAG, "Bubble sucked ! "); |
| 322 | // |
| 323 | // if (b.associated_call.getContact().isUser()) { |
| 324 | // |
| 325 | // try { |
| 326 | // if (conf.hasMultipleParticipants()) |
| 327 | // mCallbacks.getService().hangUpConference(conf.getId()); |
| 328 | // else |
| 329 | // mCallbacks.onCallEnded(conf.getParticipants().get(0)); |
| 330 | // |
| 331 | // model.clearAttractors(); |
| 332 | // } catch (RemoteException e) { |
| 333 | // e.printStackTrace(); |
| 334 | // } |
| 335 | // |
| 336 | // } else { |
| 337 | // mCallbacks.onCallEnded(b.associated_call); |
| 338 | // } |
| 339 | // bubbleRemoved(b); |
| 340 | // return true; |
| 341 | // } |
| 342 | // }, hangup_icon)); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 343 | |
Alexandre Lision | 0edf18c | 2013-09-23 17:35:50 -0400 | [diff] [blame] | 344 | // model.addAttractor(new Attractor(new PointF(model.width * .8f, model.height * 0.9f), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 345 | // @Override |
| 346 | // public boolean onBubbleSucked(Bubble b) { |
| 347 | // Log.w(TAG, "Bubble sucked ! "); |
| 348 | // makeTransfer(b); |
| 349 | // return true; |
| 350 | // } |
| 351 | // }, transfer_icon)); |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 352 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 353 | // if (conf.hasMultipleParticipants()) { |
| 354 | // model.addAttractor(new Attractor(new PointF(model.width / 1.1f, model.height * .9f), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 355 | // @Override |
| 356 | // public boolean onBubbleSucked(Bubble b) { |
| 357 | // |
| 358 | // try { |
| 359 | // mCallbacks.getService().detachParticipant(b.associated_call.getCallId()); |
| 360 | // } catch (RemoteException e) { |
| 361 | // e.printStackTrace(); |
| 362 | // } |
| 363 | // |
| 364 | // bubbleRemoved(b); |
| 365 | // return true; |
| 366 | // } |
| 367 | // }, separate_icon)); |
| 368 | // } |
| 369 | |
| 370 | // if(mCalls.size() == 1 && mCalls.get(0).isOnHold()){ |
| 371 | // mCallbacks.onCallResumed(mCalls.get(0)); |
| 372 | // } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 373 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 374 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 375 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 376 | private void initIncomingCallDisplay() { |
| 377 | Log.i(TAG, "Start incoming display"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 378 | |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 379 | mCallbacks.startTimer(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 380 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 381 | getBubbleFor(conf.getParticipants().get(0), model.width / 2, model.height / 2); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 382 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 383 | model.clearAttractors(); |
| 384 | model.addAttractor(new Attractor(new PointF(4 * model.width / 5, model.height / 2), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 385 | @Override |
| 386 | public boolean onBubbleSucked(Bubble b) { |
Alexandre Lision | a764c68 | 2013-09-09 10:02:07 -0400 | [diff] [blame] | 387 | |
| 388 | if (!accepted) { |
| 389 | mCallbacks.onCallAccepted(conf.getParticipants().get(0)); |
| 390 | accepted = true; |
| 391 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 392 | return false; |
| 393 | } |
| 394 | }, call_icon)); |
| 395 | model.addAttractor(new Attractor(new PointF(model.width / 5, model.height / 2), ATTRACTOR_SIZE, new Attractor.Callback() { |
| 396 | @Override |
| 397 | public boolean onBubbleSucked(Bubble b) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 398 | mCallbacks.onCallRejected(conf.getParticipants().get(0)); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 399 | bubbleRemoved(b); |
| 400 | return true; |
| 401 | } |
| 402 | }, hangup_icon)); |
| 403 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 404 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 405 | private void initOutGoingCallDisplay() { |
| 406 | Log.i(TAG, "Start outgoing display"); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 407 | |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 408 | mCallbacks.startTimer(); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 409 | |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 410 | getBubbleFor(myself, model.width / 2, model.height / 2); |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 411 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 412 | // TODO off-thread image loading |
| 413 | int angle_part = 360 / conf.getParticipants().size(); |
| 414 | double dX = 0; |
| 415 | double dY = 0; |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 416 | int radiusCalls = (int) (model.width / 2 - BUBBLE_SIZE); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 417 | for (int i = 0; i < conf.getParticipants().size(); ++i) { |
| 418 | dX = Math.cos(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
| 419 | dY = Math.sin(Math.toRadians(angle_part * i - 90)) * radiusCalls; |
| 420 | getBubbleFor(conf.getParticipants().get(i), (int) (model.width / 2 + dX), (int) (model.height / 2 + dY)); |
| 421 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 422 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 423 | model.clearAttractors(); |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 424 | |
Alexandre Lision | 0edf18c | 2013-09-23 17:35:50 -0400 | [diff] [blame] | 425 | // model.addAttractor(new Attractor(new PointF(model.width / 2f, model.height * .9f), 40, new Attractor.Callback() { |
| 426 | // @Override |
| 427 | // public boolean onBubbleSucked(Bubble b) { |
| 428 | // Log.w(TAG, "Bubble sucked ! "); |
| 429 | // mCallbacks.onCallEnded(conf.getParticipants().get(0)); |
| 430 | // bubbleRemoved(b); |
| 431 | // return true; |
| 432 | // } |
| 433 | // }, hangup_icon)); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 434 | } |
alision | 8570418 | 2013-05-29 15:23:03 -0400 | [diff] [blame] | 435 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 436 | /** |
| 437 | * Retrieves or create a bubble for a given contact. If the bubble exists, it is moved to the new location. |
| 438 | * |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 439 | * @param call |
| 440 | * The call associated to a contact |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 441 | * @param x |
| 442 | * Initial or new x position. |
| 443 | * @param y |
| 444 | * Initial or new y position. |
| 445 | * @return Bubble corresponding to the contact. |
| 446 | */ |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 447 | private Bubble getBubbleFor(SipCall call, float x, float y) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 448 | Bubble contact_bubble = model.getBubble(call); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 449 | if (contact_bubble != null) { |
| 450 | contact_bubble.attractor.set(x, y); |
| 451 | return contact_bubble; |
| 452 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 453 | |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 454 | contact_bubble = new Bubble(getActivity(), call, x, y, BUBBLE_SIZE); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 455 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 456 | model.addBubble(contact_bubble); |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 457 | return contact_bubble; |
| 458 | } |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 459 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 460 | /** |
| 461 | * Should be called when a bubble is removed from the model |
| 462 | */ |
| 463 | void bubbleRemoved(Bubble b) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 464 | if (b.associated_call == null) { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 465 | return; |
| 466 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 467 | } |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 468 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 469 | public void changeCallState(String callID, String newState) { |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 470 | Log.w(TAG, "Call :" + callID + " " + newState); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 471 | if (newState.contentEquals("FAILURE")) { |
| 472 | try { |
| 473 | mCallbacks.getService().hangUp(callID); |
| 474 | } catch (RemoteException e) { |
| 475 | e.printStackTrace(); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 476 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 477 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 478 | |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 479 | // Log.w(TAG, "conf.getParticipants().size():" + conf.getParticipants().size()); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 480 | for (int i = 0; i < conf.getParticipants().size(); ++i) { |
| 481 | // conf.getParticipants().get(i).printCallInfo(); |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 482 | // Log.w(TAG, "Call id:" + conf.getParticipants().get(i).getCallId()); |
| 483 | // Log.w(TAG, "Searching:" + callID); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 484 | if (callID.equals(conf.getParticipants().get(i).getCallId())) { |
| 485 | if (newState.contentEquals("HUNGUP")) { |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 486 | // Log.w(TAG, "Call hungup:" + conf.getParticipants().get(i).getContact().getmDisplayName()); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 487 | model.removeBubble(conf.getParticipants().get(i)); |
| 488 | conf.getParticipants().remove(i); |
| 489 | } else { |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 490 | // Log.w(TAG, "Call:" + conf.getParticipants().get(i).getContact().getmDisplayName() + " state:" + newState); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 491 | conf.getParticipants().get(i).setCallState(newState); |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | if (conf.isOnGoing()) |
| 497 | initNormalStateDisplay(); |
| 498 | |
| 499 | if (conf.getParticipants().size() == 0) { |
| 500 | mCallbacks.replaceCurrentCallDisplayed(); |
| 501 | } |
| 502 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 503 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 504 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 505 | public boolean draggingBubble() { |
| 506 | return view == null ? false : view.isDraggingBubble(); |
| 507 | } |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 508 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 509 | @Override |
| 510 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 511 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 512 | if (conf.getParticipants().size() == 1) { |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 513 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 514 | if (conf.getParticipants().get(0).isIncoming() && conf.getParticipants().get(0).isRinging()) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 515 | initIncomingCallDisplay(); |
| 516 | } else { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 517 | if (conf.getParticipants().get(0).isRinging()) { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 518 | initOutGoingCallDisplay(); |
| 519 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 520 | try { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 521 | if (conf.getParticipants().get(0).isOutGoing() |
| 522 | && mCallbacks.getService().getCall(conf.getParticipants().get(0).getCallId()) == null) { |
| 523 | mCallbacks.getService().placeCall(conf.getParticipants().get(0)); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 524 | initOutGoingCallDisplay(); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 525 | } else if (conf.getParticipants().get(0).isOutGoing() && conf.getParticipants().get(0).isRinging()) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 526 | initOutGoingCallDisplay(); |
| 527 | } |
| 528 | } catch (RemoteException e) { |
| 529 | Log.e(TAG, e.toString()); |
| 530 | } |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 531 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 532 | if (conf.getParticipants().get(0).isOngoing()) { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 533 | initNormalStateDisplay(); |
| 534 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 535 | } else if (conf.getParticipants().size() > 1) { |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 536 | initNormalStateDisplay(); |
| 537 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 538 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 539 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 540 | |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 541 | public void makeTransfer(Bubble contact) { |
| 542 | FragmentManager fm = getFragmentManager(); |
| 543 | TransferDFragment editName = new TransferDFragment(); |
| 544 | |
| 545 | Bundle b = new Bundle(); |
| 546 | b.putParcelableArrayList("calls", new ArrayList<Conference>()); |
| 547 | b.putParcelable("call_selected", contact.associated_call); |
| 548 | editName.setArguments(b); |
| 549 | editName.setTargetFragment(this, REQUEST_TRANSFER); |
| 550 | editName.show(fm, ""); |
Alexandre Lision | 2b23792 | 2013-09-09 16:23:02 -0400 | [diff] [blame] | 551 | } |
| 552 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 553 | @Override |
| 554 | public void surfaceCreated(SurfaceHolder holder) { |
| 555 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 556 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 557 | @Override |
| 558 | public void surfaceDestroyed(SurfaceHolder holder) { |
| 559 | } |
Adrien Béraud | 13cde0b | 2013-05-30 20:27:20 +1000 | [diff] [blame] | 560 | |
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 561 | public BubblesView getBubbleView() { |
| 562 | return view; |
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 563 | |
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 564 | } |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 565 | |
| 566 | public void updateTime() { |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 567 | long duration = System.currentTimeMillis() / 1000 - this.conf.getParticipants().get(0).getTimestamp_start(); |
Alexandre Lision | f1850c0 | 2013-09-23 14:19:34 -0400 | [diff] [blame] | 568 | callStatusTxt.setText(String.format("%d:%02d:%02d", duration / 3600, duration % 3600 / 60, duration % 60)); |
| 569 | |
| 570 | } |
| 571 | |
| 572 | @Override |
| 573 | public void onAccuracyChanged(Sensor sensor, int accuracy) { |
| 574 | Log.i(TAG, "onAccuracyChanged"); |
| 575 | |
| 576 | } |
| 577 | |
| 578 | @Override |
| 579 | public void onSensorChanged(SensorEvent event) { |
| 580 | Log.i(TAG, "onSensorChanged:" + event.sensor.getName()); |
| 581 | Log.i(TAG, "onSensorChanged:" + event.sensor.getType()); |
| 582 | if (event.values[0] == 0) { |
| 583 | // PowerManager pm = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE); |
| 584 | // pm.goToSleep(SystemClock.uptimeMillis()); |
| 585 | WindowManager.LayoutParams params = getActivity().getWindow().getAttributes(); |
| 586 | params.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
| 587 | params.screenBrightness = 0.004f; |
| 588 | getActivity().getWindow().setAttributes(params); |
| 589 | // Settings.System.putInt(getActivity().getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 1000); |
| 590 | } else { |
| 591 | WindowManager.LayoutParams params = getActivity().getWindow().getAttributes(); |
| 592 | params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; |
| 593 | params.screenBrightness = 1f; |
| 594 | getActivity().getWindow().setAttributes(params); |
| 595 | } |
| 596 | // Sensor.TYPE_PROXIMITY |
Adrien Béraud | e78d06f | 2013-09-19 13:33:44 +1000 | [diff] [blame] | 597 | |
Alexandre Lision | 0c38451 | 2013-09-17 17:15:57 -0400 | [diff] [blame] | 598 | } |
Alexandre Lision | 0edf18c | 2013-09-23 17:35:50 -0400 | [diff] [blame] | 599 | |
| 600 | public Conference getConference() { |
| 601 | return conf; |
| 602 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 603 | } |