blob: 24fe432eb0ef500a4fa9c03a0cd1b0454f16a8bf [file] [log] [blame]
Alexandre Lision40954dc2013-10-09 15:24:03 -04001package org.sflphone.model;
2
3import org.sflphone.R;
4
5import android.content.Context;
6import android.graphics.Bitmap;
7import android.graphics.Bitmap.Config;
8import android.graphics.BitmapFactory;
9import android.graphics.Canvas;
10import android.graphics.Paint;
Alexandre Lision40954dc2013-10-09 15:24:03 -040011import android.graphics.RectF;
12import android.util.Log;
13
14public class BubbleContact extends Bubble {
15
16 public SipCall associated_call;
Alexandre Lisionee2494d2013-10-09 17:14:00 -040017 Bitmap buttonMsg, buttonUnhold, buttonHold, buttonTransfer, buttonHangUp;
Alexandre Lision40954dc2013-10-09 15:24:03 -040018
Alexandre Lision68855472013-10-10 16:20:46 -040019 public interface drawerPosition {
20 int UNDEFINED = -1;
21 int TOP = 0;
22 int RIGHT = 1;
23 int BOTTOM = 2;
24 int LEFT = 3;
25 }
26
Alexandre Lision40954dc2013-10-09 15:24:03 -040027 public BubbleContact(Context context, SipCall call, float x, float y, float size) {
28 super(context, call.getContact(), x, y, size);
29 associated_call = call;
30 isUser = false;
Alexandre Lision68855472013-10-10 16:20:46 -040031 setDrawer(new ActionDrawer(0, 0, drawerPosition.UNDEFINED));
Alexandre Lision40954dc2013-10-09 15:24:03 -040032 buttonMsg = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_chat);
33 buttonHold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_pause_over_video);
Alexandre Lisionee2494d2013-10-09 17:14:00 -040034 buttonUnhold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_play_over_video);
Alexandre Lision40954dc2013-10-09 15:24:03 -040035 buttonTransfer = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_forward);
36 buttonHangUp = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_end_call);
37
38 }
39
40 @Override
41 public void expand(int width, int height) {
42
43 expanded = true;
44 generateBitmap();
45 if (pos.x < width / 3) {
46
Alexandre Lision68855472013-10-10 16:20:46 -040047 // Left
48 act = new ActionDrawer(width * 2 / 3, (int) (getRadius() * 1.5f), drawerPosition.LEFT);
49 act.adjustBounds(pos.x, pos.y);
Alexandre Lision40954dc2013-10-09 15:24:03 -040050 act.generateBitmap();
51
Alexandre Lision40954dc2013-10-09 15:24:03 -040052 } else if (pos.x > 2 * width / 3) {
Alexandre Lision68855472013-10-10 16:20:46 -040053 // Right
54 act = new ActionDrawer(width * 2 / 3, (int) (getRadius() * 1.5f), drawerPosition.RIGHT);
55 act.adjustBounds(pos.x, pos.y);
Alexandre Lision40954dc2013-10-09 15:24:03 -040056 act.generateBitmap();
57
58 } else {
59 // Middle of the screen
60 if (pos.y < height / 3) {
61 // Middle Top
62
Alexandre Lision68855472013-10-10 16:20:46 -040063 act = new ActionDrawer((int) (getRadius() * 1.5f), height / 2, drawerPosition.TOP);
64 act.adjustBounds(pos.x, pos.y);
Alexandre Lision40954dc2013-10-09 15:24:03 -040065 act.generateBitmap();
66
67 } else if (pos.y > 2 * height / 3) {
68 // Middle Bottom
69
Alexandre Lision68855472013-10-10 16:20:46 -040070 act = new ActionDrawer((int) (getRadius() * 1.5f), height / 2, drawerPosition.BOTTOM);
71 act.adjustBounds(pos.x, pos.y);
Alexandre Lision40954dc2013-10-09 15:24:03 -040072 act.generateBitmap();
73
Alexandre Lision40954dc2013-10-09 15:24:03 -040074 }
75 }
76
77 }
78
Alexandre Lisionee2494d2013-10-09 17:14:00 -040079 protected class ActionDrawer extends Bubble.ActionDrawer {
Alexandre Lision40954dc2013-10-09 15:24:03 -040080
Alexandre Lision68855472013-10-10 16:20:46 -040081 int direction;
Alexandre Lision40954dc2013-10-09 15:24:03 -040082 RectF boundsHoldButton, boundsMsgButton, boundsTransferButton, boundsHangUpButton;
83
Alexandre Lision68855472013-10-10 16:20:46 -040084 public ActionDrawer(int w, int h, int dir) {
Alexandre Lision40954dc2013-10-09 15:24:03 -040085 super(w, h);
Alexandre Lision68855472013-10-10 16:20:46 -040086 direction = dir;
Alexandre Lision40954dc2013-10-09 15:24:03 -040087 }
Alexandre Lisionee2494d2013-10-09 17:14:00 -040088
Alexandre Lision40954dc2013-10-09 15:24:03 -040089 @Override
90 public int getAction(float x, float y) {
91
92 float relativeX = x - getBounds().left;
93 float relativeY = y - getBounds().top;
94
95 if (boundsHoldButton.contains(relativeX, relativeY)) {
96 Log.i("Bubble", "Holding");
97 return actions.HOLD;
98 }
99
100 if (boundsMsgButton.contains(relativeX, relativeY)) {
101 Log.i("Bubble", "Msg");
102 return actions.MESSAGE;
103 }
104
105 if (boundsHangUpButton.contains(relativeX, relativeY)) {
106 Log.i("Bubble", "hangUp");
107 return actions.HANGUP;
108 }
109
110 if (boundsTransferButton.contains(relativeX, relativeY)) {
111 Log.i("Bubble", "Transfer");
112 return actions.TRANSFER;
113 }
114 return 0;
115
116 }
117
118 public void generateBitmap() {
119
120 img = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888);
121 Paint paint = new Paint();
122 paint.setColor(mContext.getResources().getColor(R.color.sfl_action_blue));
123 Canvas c = new Canvas(img);
124 c.drawRect(new RectF(0, 0, mWidth, mHeight), paint);
Alexandre Lision68855472013-10-10 16:20:46 -0400125 float rHeight, rWidth;
126 int wHang, hHang;
127 int wHold, hHold;
128 int wMsg, hMsg;
129 int wTrans, hTrans;
Alexandre Lision40954dc2013-10-09 15:24:03 -0400130
131 Paint pButtons = new Paint();
Alexandre Lision68855472013-10-10 16:20:46 -0400132 switch (direction) {
133 case drawerPosition.TOP:
134 rHeight = bounds.height() - getRadius();
Alexandre Lision40954dc2013-10-09 15:24:03 -0400135 boundsHoldButton = new RectF(0, getRadius(), mWidth, getRadius() + rHeight / 4);
136 boundsMsgButton = new RectF(0, getRadius() + rHeight / 4, mWidth, getRadius() + 2 * rHeight / 4);
137 boundsTransferButton = new RectF(0, getRadius() + 2 * rHeight / 4, mWidth, getRadius() + 3 * rHeight / 4);
138 boundsHangUpButton = new RectF(0, getRadius() + 3 * rHeight / 4, mWidth, getRadius() + rHeight);
139
Alexandre Lision68855472013-10-10 16:20:46 -0400140 wHang = buttonHangUp.getWidth();
141 hHang = buttonHangUp.getHeight();
Alexandre Lisionee2494d2013-10-09 17:14:00 -0400142 c.drawBitmap(buttonHangUp, null, new RectF((int) boundsHangUpButton.centerX() - wHang / 2, (int) boundsHangUpButton.centerY() - hHang
143 / 2, (int) boundsHangUpButton.centerX() + wHang / 2, (int) boundsHangUpButton.centerY() + hHang / 2), pButtons);
144
Alexandre Lision68855472013-10-10 16:20:46 -0400145 wHold = buttonHold.getWidth();
146 hHold = buttonHold.getHeight();
147 if (associated_call.isOnHold()) {
148 c.drawBitmap(buttonUnhold, null, new RectF((int) boundsHoldButton.centerX() - wHold / 2, (int) boundsHoldButton.centerY() - hHold
149 / 2, (int) boundsHoldButton.centerX() + wHold / 2, (int) boundsHoldButton.centerY() + hHold / 2), pButtons);
Alexandre Lisionee2494d2013-10-09 17:14:00 -0400150 } else {
Alexandre Lision68855472013-10-10 16:20:46 -0400151 c.drawBitmap(buttonHold, null, new RectF((int) boundsHoldButton.centerX() - wHold / 2, (int) boundsHoldButton.centerY() - hHold
152 / 2, (int) boundsHoldButton.centerX() + wHold / 2, (int) boundsHoldButton.centerY() + hHold / 2), pButtons);
Alexandre Lisionee2494d2013-10-09 17:14:00 -0400153 }
Alexandre Lisionee2494d2013-10-09 17:14:00 -0400154
Alexandre Lision68855472013-10-10 16:20:46 -0400155 wMsg = buttonMsg.getWidth();
156 hMsg = buttonMsg.getHeight();
Alexandre Lisionee2494d2013-10-09 17:14:00 -0400157
158 c.drawBitmap(buttonMsg, null, new RectF((int) boundsMsgButton.centerX() - wMsg / 2, (int) boundsMsgButton.centerY() - hMsg / 2,
159 (int) boundsMsgButton.centerX() + wMsg / 2, (int) boundsMsgButton.centerY() + hMsg / 2), pButtons);
160
Alexandre Lision68855472013-10-10 16:20:46 -0400161 wTrans = buttonTransfer.getWidth();
162 hTrans = buttonTransfer.getHeight();
Alexandre Lision40954dc2013-10-09 15:24:03 -0400163
Alexandre Lisionee2494d2013-10-09 17:14:00 -0400164 c.drawBitmap(buttonTransfer, null, new RectF((int) boundsTransferButton.centerX() - wTrans / 2, (int) boundsTransferButton.centerY()
165 - hTrans / 2, (int) boundsTransferButton.centerX() + wTrans / 2, (int) boundsTransferButton.centerY() + hTrans / 2), pButtons);
Alexandre Lision68855472013-10-10 16:20:46 -0400166 break;
167 case drawerPosition.BOTTOM:
168 rHeight = bounds.height() - getRadius();
169 boundsHoldButton = new RectF(0, 0, mWidth, rHeight / 4);
170 boundsMsgButton = new RectF(0, rHeight / 4, mWidth, 2 * rHeight / 4);
171 boundsTransferButton = new RectF(0, 2 * rHeight / 4, mWidth, 3 * rHeight / 4);
172 boundsHangUpButton = new RectF(0, 3 * rHeight / 4, mWidth, rHeight);
173
174 wHang = buttonHangUp.getWidth();
175 hHang = buttonHangUp.getHeight();
176 c.drawBitmap(buttonHangUp, null, new RectF((int) boundsHangUpButton.centerX() - wHang / 2, (int) boundsHangUpButton.centerY() - hHang
177 / 2, (int) boundsHangUpButton.centerX() + wHang / 2, (int) boundsHangUpButton.centerY() + hHang / 2), pButtons);
178
179 wHold = buttonHold.getWidth();
180 hHold = buttonHold.getHeight();
181 if (associated_call.isOnHold()) {
182 c.drawBitmap(buttonUnhold, null, new RectF((int) boundsHoldButton.centerX() - wHold / 2, (int) boundsHoldButton.centerY() - hHold
183 / 2, (int) boundsHoldButton.centerX() + wHold / 2, (int) boundsHoldButton.centerY() + hHold / 2), pButtons);
184 } else {
185 c.drawBitmap(buttonHold, null, new RectF((int) boundsHoldButton.centerX() - wHold / 2, (int) boundsHoldButton.centerY() - hHold
186 / 2, (int) boundsHoldButton.centerX() + wHold / 2, (int) boundsHoldButton.centerY() + hHold / 2), pButtons);
187 }
188
189 wMsg = buttonMsg.getWidth();
190 hMsg = buttonMsg.getHeight();
191
192 c.drawBitmap(buttonMsg, null, new RectF((int) boundsMsgButton.centerX() - wMsg / 2, (int) boundsMsgButton.centerY() - hMsg / 2,
193 (int) boundsMsgButton.centerX() + wMsg / 2, (int) boundsMsgButton.centerY() + hMsg / 2), pButtons);
194
195 wTrans = buttonTransfer.getWidth();
196 hTrans = buttonTransfer.getHeight();
197
198 c.drawBitmap(buttonTransfer, null, new RectF((int) boundsTransferButton.centerX() - wTrans / 2, (int) boundsTransferButton.centerY()
199 - hTrans / 2, (int) boundsTransferButton.centerX() + wTrans / 2, (int) boundsTransferButton.centerY() + hTrans / 2), pButtons);
200 break;
201 case drawerPosition.RIGHT:
202 rWidth = bounds.width() - getRadius();
203 boundsHoldButton = new RectF(0, 0, rWidth / 4, mHeight);
204 boundsMsgButton = new RectF(rWidth / 4, 0, 2 * rWidth / 4, mHeight);
205 boundsTransferButton = new RectF(2 * rWidth / 4, 0, 3 * rWidth / 4, mHeight);
206 boundsHangUpButton = new RectF(3 * rWidth / 4, 0, rWidth, mHeight);
207
208 wHang = buttonHangUp.getWidth();
209 hHang = buttonHangUp.getHeight();
210 c.drawBitmap(buttonHangUp, null, new RectF((int) boundsHangUpButton.centerX() - wHang / 2, (int) boundsHangUpButton.centerY() - hHang
211 / 2, (int) boundsHangUpButton.centerX() + wHang / 2, (int) boundsHangUpButton.centerY() + hHang / 2), pButtons);
212
213 wHold = buttonHold.getWidth();
214 hHold = buttonHold.getHeight();
215 if (associated_call.isOnHold()) {
216 c.drawBitmap(buttonUnhold, null, new RectF((int) boundsHoldButton.centerX() - wHold / 2, (int) boundsHoldButton.centerY() - hHold
217 / 2, (int) boundsHoldButton.centerX() + wHold / 2, (int) boundsHoldButton.centerY() + hHold / 2), pButtons);
218 } else {
219 c.drawBitmap(buttonHold, null, new RectF((int) boundsHoldButton.centerX() - wHold / 2, (int) boundsHoldButton.centerY() - hHold
220 / 2, (int) boundsHoldButton.centerX() + wHold / 2, (int) boundsHoldButton.centerY() + hHold / 2), pButtons);
221 }
222
223 wMsg = buttonMsg.getWidth();
224 hMsg = buttonMsg.getHeight();
225
226 c.drawBitmap(buttonMsg, null, new RectF((int) boundsMsgButton.centerX() - wMsg / 2, (int) boundsMsgButton.centerY() - hMsg / 2,
227 (int) boundsMsgButton.centerX() + wMsg / 2, (int) boundsMsgButton.centerY() + hMsg / 2), pButtons);
228
229 wTrans = buttonTransfer.getWidth();
230 hTrans = buttonTransfer.getHeight();
231
232 c.drawBitmap(buttonTransfer, null, new RectF((int) boundsTransferButton.centerX() - wTrans / 2, (int) boundsTransferButton.centerY()
233 - hTrans / 2, (int) boundsTransferButton.centerX() + wTrans / 2, (int) boundsTransferButton.centerY() + hTrans / 2), pButtons);
234 break;
235 case drawerPosition.LEFT:
236 rWidth = bounds.width() - getRadius();
237 boundsHoldButton = new RectF(getRadius(), 0, getRadius() + rWidth / 4, mHeight);
238 boundsMsgButton = new RectF(getRadius() + rWidth / 4, 0, getRadius() + 2 * rWidth / 4, mHeight);
239 boundsTransferButton = new RectF(getRadius() + 2 * rWidth / 4, 0, getRadius() + 3 * rWidth / 4, mHeight);
240 boundsHangUpButton = new RectF(getRadius() + 3 * rWidth / 4, 0, getRadius() + rWidth, mHeight);
241
242 wHang = buttonHangUp.getWidth();
243 hHang = buttonHangUp.getHeight();
244 c.drawBitmap(buttonHangUp, null, new RectF((int) boundsHangUpButton.centerX() - wHang / 2, (int) boundsHangUpButton.centerY() - hHang
245 / 2, (int) boundsHangUpButton.centerX() + wHang / 2, (int) boundsHangUpButton.centerY() + hHang / 2), pButtons);
246
247 wHold = buttonHold.getWidth();
248 hHold = buttonHold.getHeight();
249 if (associated_call.isOnHold()) {
250 c.drawBitmap(buttonUnhold, null, new RectF((int) boundsHoldButton.centerX() - wHold / 2, (int) boundsHoldButton.centerY() - hHold
251 / 2, (int) boundsHoldButton.centerX() + wHold / 2, (int) boundsHoldButton.centerY() + hHold / 2), pButtons);
252 } else {
253 c.drawBitmap(buttonHold, null, new RectF((int) boundsHoldButton.centerX() - wHold / 2, (int) boundsHoldButton.centerY() - hHold
254 / 2, (int) boundsHoldButton.centerX() + wHold / 2, (int) boundsHoldButton.centerY() + hHold / 2), pButtons);
255 }
256
257 wMsg = buttonMsg.getWidth();
258 hMsg = buttonMsg.getHeight();
259
260 c.drawBitmap(buttonMsg, null, new RectF((int) boundsMsgButton.centerX() - wMsg / 2, (int) boundsMsgButton.centerY() - hMsg / 2,
261 (int) boundsMsgButton.centerX() + wMsg / 2, (int) boundsMsgButton.centerY() + hMsg / 2), pButtons);
262
263 wTrans = buttonTransfer.getWidth();
264 hTrans = buttonTransfer.getHeight();
265
266 c.drawBitmap(buttonTransfer, null, new RectF((int) boundsTransferButton.centerX() - wTrans / 2, (int) boundsTransferButton.centerY()
267 - hTrans / 2, (int) boundsTransferButton.centerX() + wTrans / 2, (int) boundsTransferButton.centerY() + hTrans / 2), pButtons);
268 break;
Alexandre Lision40954dc2013-10-09 15:24:03 -0400269 }
270
271 }
272
Alexandre Lision68855472013-10-10 16:20:46 -0400273 public void adjustBounds(float x, float y) {
274 switch (direction) {
275 case drawerPosition.TOP:
276 setBounds(x - getRadius(), y, x + getRadius(), y + getHeight());
277 break;
278 case drawerPosition.BOTTOM:
279 setBounds(x - getRadius(), y - getHeight(), x + getRadius(), y);
280 break;
281 case drawerPosition.RIGHT:
282 setBounds(x - getWidth(), y - getRadius(), x, y + +getRadius());
283 break;
284 case drawerPosition.LEFT:
285 setBounds(x, y - getRadius(), x + getWidth(), y + getRadius());
286 break;
287 }
288
289 }
290
291 @Override
292 public void setBounds(float left, float top, float right, float bottom) {
293 int margin = (int) (0.5f * getRadius()) / 2;
294 switch (direction) {
295 case drawerPosition.TOP:
296 case drawerPosition.BOTTOM:
297 super.setBounds(left + margin, top, right - margin, bottom);
298 break;
299 case drawerPosition.RIGHT:
300 case drawerPosition.LEFT:
301 super.setBounds(left, top + margin, right, bottom - margin);
302 break;
303 }
304
305 }
Alexandre Lision40954dc2013-10-09 15:24:03 -0400306 }
307
308 public Bitmap getDrawerBitmap() {
309 return act.getBitmap();
310 }
311
312 public RectF getDrawerBounds() {
313 return act.getBounds();
314 }
315
316 @Override
317 public void set(float x, float y, float s) {
318 scale = s;
319 pos.x = x;
320 pos.y = y;
321 if (!expanded) {
322 bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius());
323 } else {
324 bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius());
Alexandre Lision68855472013-10-10 16:20:46 -0400325 act.adjustBounds(pos.x, pos.y);
Alexandre Lision40954dc2013-10-09 15:24:03 -0400326 }
327 }
328
329 @Override
330 public int getRadius() {
331 return (int) (radius * scale * density);
332 }
333
Alexandre Lision40954dc2013-10-09 15:24:03 -0400334 @Override
335 public boolean getHoldStatus() {
336 if (associated_call.isOnHold())
337 return true;
338 else
339 return false;
340 }
341
342 @Override
343 public boolean getRecordStatus() {
344 if (associated_call.isRecording())
345 return true;
346 else
347 return false;
348 }
349
Alexandre Lision40954dc2013-10-09 15:24:03 -0400350 public SipCall getCall() {
351 return associated_call;
352 }
353
Alexandre Lisionee2494d2013-10-09 17:14:00 -0400354 public void setCall(SipCall call) {
355 associated_call = call;
Alexandre Lision68855472013-10-10 16:20:46 -0400356 if (expanded) {
Alexandre Lisionee2494d2013-10-09 17:14:00 -0400357 act.generateBitmap();
358 }
Alexandre Lision68855472013-10-10 16:20:46 -0400359
Alexandre Lisionee2494d2013-10-09 17:14:00 -0400360 }
361
362 @Override
Alexandre Lision68855472013-10-10 16:20:46 -0400363 public String getName() {
364 return associated_call.getContact().getmDisplayName();
365 }
366
367 @Override
368 public boolean callIDEquals(String call) {
369 return associated_call.getCallId().contentEquals(call);
370 }
371
372 @Override
373 public String getCallID() {
374 return associated_call.getCallId();
Alexandre Lisionee2494d2013-10-09 17:14:00 -0400375 }
376
Alexandre Lision40954dc2013-10-09 15:24:03 -0400377}