blob: 528afb54c2d4f345fcf7646eeb50d5b245e9430a [file] [log] [blame]
Alexandre Lisiona8b78722013-12-13 10:18:33 -05001/*
Alexandre Lisionc1024c02014-01-06 11:12:53 -05002 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
Alexandre Lisiona8b78722013-12-13 10:18:33 -05003 *
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
Alexandre Lision40954dc2013-10-09 15:24:03 -040032package org.sflphone.model;
33
34import org.sflphone.R;
35
36import android.content.Context;
37import android.graphics.Bitmap;
38import android.graphics.Bitmap.Config;
39import android.graphics.BitmapFactory;
40import android.graphics.Canvas;
Alexandre Lision40954dc2013-10-09 15:24:03 -040041import android.graphics.RectF;
42import android.util.Log;
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -040043import android.view.MotionEvent;
Alexandre Lision40954dc2013-10-09 15:24:03 -040044
45public class BubbleUser extends Bubble {
46
47 public Conference associated_call;
Alexandre Lision1a682572013-11-01 11:21:17 -040048
Alexandre Lision40954dc2013-10-09 15:24:03 -040049 float expanded_radius;
50
Alexandre Lisionc9fca9e2013-11-08 15:21:18 -050051 private boolean mMuted;
52
Alexandre Lision68855472013-10-10 16:20:46 -040053 public BubbleUser(Context context, CallContact m, Conference conf, float x, float y, float size) {
54 super(context, m, x, y, size);
Alexandre Lision40954dc2013-10-09 15:24:03 -040055 isUser = true;
56 associated_call = conf;
Alexandre Lisionc9fca9e2013-11-08 15:21:18 -050057 mMuted = false;
Alexandre Lision40954dc2013-10-09 15:24:03 -040058 expanded_radius = (float) (size * 1.5);
59
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -040060 setDrawer(new ActionDrawer(0, 0));
Alexandre Lision40954dc2013-10-09 15:24:03 -040061 }
62
63 @Override
64 public void set(float x, float y, float s) {
65 scale = s;
66 pos.x = x;
67 pos.y = y;
68 bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius());
69 if (!expanded) {
70 bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius());
71 } else {
72 bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius());
73 act.setBounds(pos.x - getExpandedRadius(), pos.y - getExpandedRadius(), pos.x + getExpandedRadius(), pos.y + getExpandedRadius());
74 }
75 }
76
77 @Override
78 public void expand(int width, int height) {
79
80 expanded = true;
81 generateBitmap();
82 setDrawer(new ActionDrawer((int) getExpandedRadius() * 2, (int) getExpandedRadius() * 2));
83
84 act.setBounds(pos.x - getExpandedRadius(), pos.y - getExpandedRadius(), pos.x + getExpandedRadius(), pos.y + getExpandedRadius());
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -040085 act.generateBitmap(actions.NOTHING);
Alexandre Lision40954dc2013-10-09 15:24:03 -040086
87 }
88
89 @Override
90 public int getRadius() {
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -040091 if (expanded)
Alexandre Lisiona9485b82013-10-25 10:00:57 -040092 return (int) (radius * density);
Alexandre Lision40954dc2013-10-09 15:24:03 -040093 return (int) (radius * scale * density);
94 }
95
96 public int getExpandedRadius() {
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -040097 return (int) (expanded_radius * density);
Alexandre Lision40954dc2013-10-09 15:24:03 -040098 }
99
100 @Override
101 public boolean getHoldStatus() {
102 if (associated_call.isOnHold())
103 return true;
104 else
105 return false;
106 }
107
108 @Override
109 public boolean getRecordStatus() {
110 if (associated_call.isRecording())
111 return true;
112 else
113 return false;
114 }
115
Alexandre Lision68855472013-10-10 16:20:46 -0400116 // @Override
117 public Conference getConference() {
118 return associated_call;
Alexandre Lision40954dc2013-10-09 15:24:03 -0400119 }
120
121 protected class ActionDrawer extends Bubble.ActionDrawer {
122
Alexandre Lision1a682572013-11-01 11:21:17 -0400123 RectF boundsHoldButton, boundsMicButton, boundsRecButton, boundsHangUpButton;
124
125 Bitmap buttonMic, buttonMicMuted, buttonHold, buttonUnhold, buttonRec, buttonHangUp;
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400126 int wHang, hHang;
127 int wHold, hHold;
128 int wMic, hMic;
Alexandre Lision1a682572013-11-01 11:21:17 -0400129 int wRec, hRec;
Alexandre Lisiond5ee3962013-11-08 15:37:28 -0500130
131 float delta;
132
133 private RectF globals;
Alexandre Lision40954dc2013-10-09 15:24:03 -0400134
135 public ActionDrawer(int w, int h) {
136 super(w, h);
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400137
Alexandre Lisiond5ee3962013-11-08 15:37:28 -0500138 delta = (float) (w / 2 * Math.cos(Math.toRadians(45d)));
139 globals = new RectF(0, 0, mWidth, mHeight);
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400140
Alexandre Lision1a682572013-11-01 11:21:17 -0400141 buttonMic = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_mic);
142 buttonMicMuted = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_mic_muted);
143 buttonHold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_pause_over_video);
144 buttonUnhold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_play_over_video);
145 buttonRec = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.recordpressed);
146 buttonHangUp = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_end_call);
147
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400148 wHang = buttonHangUp.getWidth();
149 hHang = buttonHangUp.getHeight();
150
151 wHold = buttonHold.getWidth();
152 hHold = buttonHold.getHeight();
153
154 wMic = buttonMic.getWidth();
155 hMic = buttonMic.getHeight();
Alexandre Lision1a682572013-11-01 11:21:17 -0400156
157 wRec = buttonRec.getWidth();
158 hRec = buttonRec.getHeight();
Alexandre Lision40954dc2013-10-09 15:24:03 -0400159 }
160
161 @Override
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400162 public void generateBitmap(int action) {
Alexandre Lision40954dc2013-10-09 15:24:03 -0400163 img = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888);
Alexandre Lision40954dc2013-10-09 15:24:03 -0400164 Canvas c = new Canvas(img);
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400165 c.drawOval(new RectF(0, 0, mWidth, mHeight), mBackgroundPaint);
Alexandre Lision40954dc2013-10-09 15:24:03 -0400166
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400167 drawHangUp(c, action == actions.HANGUP);
168 drawHold(c, action == actions.HOLD);
169 drawMute(c, action == actions.MUTE);
Alexandre Lision1a682572013-11-01 11:21:17 -0400170 drawRec(c, action == actions.RECORD);
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400171
Alexandre Lisiond5ee3962013-11-08 15:37:28 -0500172 c.drawLine(mWidth / 2 - delta, mHeight / 2 - delta, mWidth / 2 + delta, mHeight / 2 + delta, mLines);
173 c.drawLine(mWidth / 2 - delta, mHeight / 2 + delta, mWidth / 2 + delta, mHeight / 2 - delta, mLines);
174
Alexandre Lision40954dc2013-10-09 15:24:03 -0400175 }
176
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400177 private void drawHangUp(Canvas c, boolean selected) {
178 boundsHangUpButton = new RectF(mWidth / 2 - getRadius(), 0, mWidth / 2 + getRadius(), mHeight / 2 - getRadius());
179
180 RectF boundsHangUpIcon = new RectF((int) boundsHangUpButton.centerX() - wHang / 2, (int) boundsHangUpButton.centerY() - hHang / 2,
181 (int) boundsHangUpButton.centerX() + wHang / 2, (int) boundsHangUpButton.centerY() + hHang / 2);
182
183 if (selected) {
Alexandre Lisiond5ee3962013-11-08 15:37:28 -0500184 c.drawArc(globals, 225, 90, true, mSelector);
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400185 }
186
187 c.drawBitmap(buttonHangUp, null, boundsHangUpIcon, mButtonPaint);
188 }
189
190 private void drawHold(Canvas c, boolean selected) {
191 boundsHoldButton = new RectF(0, mHeight / 2 - getRadius(), mWidth / 2 - getRadius(), mHeight / 2 + getRadius());
192 RectF boundsHoldIcon = new RectF((int) boundsHoldButton.centerX() - wHold / 2, (int) boundsHoldButton.centerY() - hHold / 2,
193 (int) boundsHoldButton.centerX() + wHold / 2, (int) boundsHoldButton.centerY() + hHold / 2);
194 if (selected) {
Alexandre Lisiond5ee3962013-11-08 15:37:28 -0500195 c.drawArc(globals, 135, 90, true, mSelector);
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400196 }
197
198 if (associated_call.isOnHold()) {
199 c.drawBitmap(buttonUnhold, null, boundsHoldIcon, mButtonPaint);
200 } else {
201 c.drawBitmap(buttonHold, null, boundsHoldIcon, mButtonPaint);
202 }
203 }
204
205 private void drawMute(Canvas c, boolean selected) {
206 boundsMicButton = new RectF(mWidth / 2 + getRadius(), mHeight / 2 - getRadius(), mWidth, mHeight / 2 + getRadius());
207 RectF boundsMuteIcon = new RectF((int) boundsMicButton.centerX() - wMic / 2, (int) boundsMicButton.centerY() - hMic / 2,
208 (int) boundsMicButton.centerX() + wMic / 2, (int) boundsMicButton.centerY() + hMic / 2);
Alexandre Lisiond5ee3962013-11-08 15:37:28 -0500209 if (selected || mMuted) {
210 c.drawArc(globals, -45, 90, true, mSelector);
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400211 }
212
213 c.drawBitmap(buttonMic, null, boundsMuteIcon, mButtonPaint);
214 }
215
Alexandre Lision1a682572013-11-01 11:21:17 -0400216 private void drawRec(Canvas c, boolean selected) {
217 boundsRecButton = new RectF(mWidth / 2 - getRadius(), mHeight / 2 + getRadius(), mWidth / 2 + getRadius(), mHeight);
218 RectF boundsRecIcon = new RectF((int) boundsRecButton.centerX() - wRec / 2, (int) boundsRecButton.centerY() - hRec / 2,
219 (int) boundsRecButton.centerX() + wRec / 2, (int) boundsRecButton.centerY() + hMic / 2);
220 if (selected || associated_call.isRecording()) {
Alexandre Lisiond5ee3962013-11-08 15:37:28 -0500221 c.drawArc(globals, 45, 90, true, mSelector);
Alexandre Lision1a682572013-11-01 11:21:17 -0400222 }
223
224 c.drawBitmap(buttonRec, null, boundsRecIcon, mButtonPaint);
225 }
226
Alexandre Lision40954dc2013-10-09 15:24:03 -0400227 @Override
228 public int getAction(float x, float y) {
229
Alexandre Lision5cd659e2013-10-29 13:18:23 -0400230 float relativeX = x - getDrawerBounds().left;
231 float relativeY = y - getDrawerBounds().top;
Alexandre Lision40954dc2013-10-09 15:24:03 -0400232
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400233 if (!getDrawerBounds().contains(x, y) && !getBounds().contains(x, y)) {
Alexandre Lision5cd659e2013-10-29 13:18:23 -0400234 return actions.OUT_OF_BOUNDS;
235 }
Alexandre Lision40954dc2013-10-09 15:24:03 -0400236
237 if (boundsHoldButton.contains(relativeX, relativeY)) {
238 Log.i("Bubble", "Holding");
239 return actions.HOLD;
240 }
241
Alexandre Lision1a682572013-11-01 11:21:17 -0400242 if (boundsRecButton.contains(relativeX, relativeY)) {
243 Log.i("Bubble", "Record");
244 return actions.RECORD;
245 }
Alexandre Lision40954dc2013-10-09 15:24:03 -0400246
Alexandre Lision68855472013-10-10 16:20:46 -0400247 if (boundsMicButton.contains(relativeX, relativeY)) {
Alexandre Lision40954dc2013-10-09 15:24:03 -0400248 Log.i("Bubble", "Muting");
249 return actions.MUTE;
250 }
251
Alexandre Lision68855472013-10-10 16:20:46 -0400252 if (boundsHangUpButton.contains(relativeX, relativeY)) {
Alexandre Lision40954dc2013-10-09 15:24:03 -0400253 Log.i("Bubble", "hangup");
254 return actions.HANGUP;
255 }
256
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400257 return actions.NOTHING;
Alexandre Lision40954dc2013-10-09 15:24:03 -0400258
259 }
260
261 }
262
263 @Override
264 public Bitmap getDrawerBitmap() {
265 return act.img;
266 }
267
268 @Override
269 public RectF getDrawerBounds() {
270 return act.bounds;
271 }
272
Alexandre Lision68855472013-10-10 16:20:46 -0400273 public void setConference(Conference c) {
274 associated_call = c;
Alexandre Lisiona9485b82013-10-25 10:00:57 -0400275 if (expanded) {
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400276 act.generateBitmap(actions.NOTHING);
Alexandre Lisiona9485b82013-10-25 10:00:57 -0400277 }
Alexandre Lisionee2494d2013-10-09 17:14:00 -0400278 }
279
280 @Override
Alexandre Lision68855472013-10-10 16:20:46 -0400281 public String getName() {
282 return mContext.getResources().getString(R.string.me);
283 }
284
285 @Override
286 public boolean callIDEquals(String call) {
287 return associated_call.getId().contentEquals(call);
288 }
289
290 @Override
291 public String getCallID() {
292 if (associated_call.hasMultipleParticipants())
293 return associated_call.getId();
294 else
295 return associated_call.getParticipants().get(0).getCallId();
296 }
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400297
Alexandre Lision68855472013-10-10 16:20:46 -0400298 @Override
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400299 public boolean isConference() {
Alexandre Lision68855472013-10-10 16:20:46 -0400300 return associated_call.hasMultipleParticipants();
Alexandre Lisionee2494d2013-10-09 17:14:00 -0400301 }
302
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400303 @Override
304 public boolean onDown(MotionEvent event) {
305 if (expanded) {
306 act.generateBitmap(act.getAction(event.getX(), event.getY()));
307 return false;
308 }
309
310 if (intersects(event.getX(), event.getY())) {
311 dragged = true;
312 last_drag = System.nanoTime();
313 setPos(event.getX(), event.getY());
314 target_scale = .8f;
315 return true;
316 }
317 return false;
318 }
Alexandre Lisionc9fca9e2013-11-08 15:21:18 -0500319
320 public boolean getMute() {
321 return mMuted;
322 }
323
324 public void toggleMute() {
325 mMuted = !mMuted;
326 act.generateBitmap(Bubble.actions.NOTHING);
327
328 }
329
330 public void setMute(boolean captureMuted) {
331 mMuted = captureMuted;
Alexandre Lisionc9fca9e2013-11-08 15:21:18 -0500332 }
Alexandre Lision40954dc2013-10-09 15:24:03 -0400333}