blob: 77616a760ccf793ad9a2fe7f817ef4c627800e96 [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 Lision1a682572013-11-01 11:21:17 -040011import android.graphics.Paint.Style;
Alexandre Lision40954dc2013-10-09 15:24:03 -040012import android.graphics.RectF;
13import android.util.Log;
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -040014import android.view.MotionEvent;
Alexandre Lision40954dc2013-10-09 15:24:03 -040015
16public class BubbleUser extends Bubble {
17
18 public Conference associated_call;
Alexandre Lision1a682572013-11-01 11:21:17 -040019
Alexandre Lision40954dc2013-10-09 15:24:03 -040020 float expanded_radius;
21
Alexandre Lision68855472013-10-10 16:20:46 -040022 public BubbleUser(Context context, CallContact m, Conference conf, float x, float y, float size) {
23 super(context, m, x, y, size);
Alexandre Lision40954dc2013-10-09 15:24:03 -040024 isUser = true;
25 associated_call = conf;
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -040026
Alexandre Lision40954dc2013-10-09 15:24:03 -040027 expanded_radius = (float) (size * 1.5);
28
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -040029 setDrawer(new ActionDrawer(0, 0));
Alexandre Lision40954dc2013-10-09 15:24:03 -040030 }
31
32 @Override
33 public void set(float x, float y, float s) {
34 scale = s;
35 pos.x = x;
36 pos.y = y;
37 bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius());
38 if (!expanded) {
39 bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius());
40 } else {
41 bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius());
42 act.setBounds(pos.x - getExpandedRadius(), pos.y - getExpandedRadius(), pos.x + getExpandedRadius(), pos.y + getExpandedRadius());
43 }
44 }
45
46 @Override
47 public void expand(int width, int height) {
48
49 expanded = true;
50 generateBitmap();
51 setDrawer(new ActionDrawer((int) getExpandedRadius() * 2, (int) getExpandedRadius() * 2));
52
53 act.setBounds(pos.x - getExpandedRadius(), pos.y - getExpandedRadius(), pos.x + getExpandedRadius(), pos.y + getExpandedRadius());
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -040054 act.generateBitmap(actions.NOTHING);
Alexandre Lision40954dc2013-10-09 15:24:03 -040055
56 }
57
58 @Override
59 public int getRadius() {
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -040060 if (expanded)
Alexandre Lisiona9485b82013-10-25 10:00:57 -040061 return (int) (radius * density);
Alexandre Lision40954dc2013-10-09 15:24:03 -040062 return (int) (radius * scale * density);
63 }
64
65 public int getExpandedRadius() {
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -040066 return (int) (expanded_radius * density);
Alexandre Lision40954dc2013-10-09 15:24:03 -040067 }
68
69 @Override
70 public boolean getHoldStatus() {
71 if (associated_call.isOnHold())
72 return true;
73 else
74 return false;
75 }
76
77 @Override
78 public boolean getRecordStatus() {
79 if (associated_call.isRecording())
80 return true;
81 else
82 return false;
83 }
84
Alexandre Lision68855472013-10-10 16:20:46 -040085 // @Override
86 public Conference getConference() {
87 return associated_call;
Alexandre Lision40954dc2013-10-09 15:24:03 -040088 }
89
90 protected class ActionDrawer extends Bubble.ActionDrawer {
91
Alexandre Lision1a682572013-11-01 11:21:17 -040092 RectF boundsHoldButton, boundsMicButton, boundsRecButton, boundsHangUpButton;
93
94 Bitmap buttonMic, buttonMicMuted, buttonHold, buttonUnhold, buttonRec, buttonHangUp;
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -040095 int wHang, hHang;
96 int wHold, hHold;
97 int wMic, hMic;
Alexandre Lision1a682572013-11-01 11:21:17 -040098 int wRec, hRec;
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -040099 Paint mBackgroundPaint;
100 Paint mSelector;
101 Paint mButtonPaint;
Alexandre Lision40954dc2013-10-09 15:24:03 -0400102
103 public ActionDrawer(int w, int h) {
104 super(w, h);
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400105 mBackgroundPaint = new Paint();
106 mBackgroundPaint.setColor(mContext.getResources().getColor(R.color.sfl_blue_9));
107 mBackgroundPaint.setDither(true);
108
109 mSelector = new Paint();
110 mSelector.setStyle(Style.FILL);
Alexandre Lision1888bf32013-10-31 09:51:41 -0400111 mSelector.setColor(mContext.getResources().getColor(R.color.sfl_blue_9));
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400112
113 mButtonPaint = new Paint();
114
Alexandre Lision1a682572013-11-01 11:21:17 -0400115 buttonMic = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_mic);
116 buttonMicMuted = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_mic_muted);
117 buttonHold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_pause_over_video);
118 buttonUnhold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_play_over_video);
119 buttonRec = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.recordpressed);
120 buttonHangUp = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_end_call);
121
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400122 wHang = buttonHangUp.getWidth();
123 hHang = buttonHangUp.getHeight();
124
125 wHold = buttonHold.getWidth();
126 hHold = buttonHold.getHeight();
127
128 wMic = buttonMic.getWidth();
129 hMic = buttonMic.getHeight();
Alexandre Lision1a682572013-11-01 11:21:17 -0400130
131 wRec = buttonRec.getWidth();
132 hRec = buttonRec.getHeight();
Alexandre Lision40954dc2013-10-09 15:24:03 -0400133 }
134
135 @Override
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400136 public void generateBitmap(int action) {
Alexandre Lision40954dc2013-10-09 15:24:03 -0400137 img = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888);
Alexandre Lision40954dc2013-10-09 15:24:03 -0400138 Canvas c = new Canvas(img);
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400139 c.drawOval(new RectF(0, 0, mWidth, mHeight), mBackgroundPaint);
Alexandre Lision40954dc2013-10-09 15:24:03 -0400140
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400141 drawHangUp(c, action == actions.HANGUP);
142 drawHold(c, action == actions.HOLD);
143 drawMute(c, action == actions.MUTE);
Alexandre Lision1a682572013-11-01 11:21:17 -0400144 drawRec(c, action == actions.RECORD);
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400145
Alexandre Lision40954dc2013-10-09 15:24:03 -0400146 }
147
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400148 private void drawHangUp(Canvas c, boolean selected) {
149 boundsHangUpButton = new RectF(mWidth / 2 - getRadius(), 0, mWidth / 2 + getRadius(), mHeight / 2 - getRadius());
150
151 RectF boundsHangUpIcon = new RectF((int) boundsHangUpButton.centerX() - wHang / 2, (int) boundsHangUpButton.centerY() - hHang / 2,
152 (int) boundsHangUpButton.centerX() + wHang / 2, (int) boundsHangUpButton.centerY() + hHang / 2);
153
154 if (selected) {
155 c.drawCircle(boundsHangUpButton.centerX(), boundsHangUpButton.centerY(), boundsHangUpButton.width() / 2, mSelector);
156 }
157
158 c.drawBitmap(buttonHangUp, null, boundsHangUpIcon, mButtonPaint);
159 }
160
161 private void drawHold(Canvas c, boolean selected) {
162 boundsHoldButton = new RectF(0, mHeight / 2 - getRadius(), mWidth / 2 - getRadius(), mHeight / 2 + getRadius());
163 RectF boundsHoldIcon = new RectF((int) boundsHoldButton.centerX() - wHold / 2, (int) boundsHoldButton.centerY() - hHold / 2,
164 (int) boundsHoldButton.centerX() + wHold / 2, (int) boundsHoldButton.centerY() + hHold / 2);
165 if (selected) {
166 c.drawCircle(boundsHoldButton.centerX(), boundsHoldButton.centerY(), boundsHoldButton.width() / 2, mSelector);
167 }
168
169 if (associated_call.isOnHold()) {
170 c.drawBitmap(buttonUnhold, null, boundsHoldIcon, mButtonPaint);
171 } else {
172 c.drawBitmap(buttonHold, null, boundsHoldIcon, mButtonPaint);
173 }
174 }
175
176 private void drawMute(Canvas c, boolean selected) {
177 boundsMicButton = new RectF(mWidth / 2 + getRadius(), mHeight / 2 - getRadius(), mWidth, mHeight / 2 + getRadius());
178 RectF boundsMuteIcon = new RectF((int) boundsMicButton.centerX() - wMic / 2, (int) boundsMicButton.centerY() - hMic / 2,
179 (int) boundsMicButton.centerX() + wMic / 2, (int) boundsMicButton.centerY() + hMic / 2);
180 if (selected) {
181 c.drawCircle(boundsMicButton.centerX(), boundsMicButton.centerY(), boundsMicButton.width() / 2, mSelector);
182 }
183
184 c.drawBitmap(buttonMic, null, boundsMuteIcon, mButtonPaint);
185 }
186
Alexandre Lision1a682572013-11-01 11:21:17 -0400187 private void drawRec(Canvas c, boolean selected) {
188 boundsRecButton = new RectF(mWidth / 2 - getRadius(), mHeight / 2 + getRadius(), mWidth / 2 + getRadius(), mHeight);
189 RectF boundsRecIcon = new RectF((int) boundsRecButton.centerX() - wRec / 2, (int) boundsRecButton.centerY() - hRec / 2,
190 (int) boundsRecButton.centerX() + wRec / 2, (int) boundsRecButton.centerY() + hMic / 2);
191 if (selected || associated_call.isRecording()) {
192 c.drawCircle(boundsRecButton.centerX(), boundsRecButton.centerY(), boundsRecButton.width() / 2, mSelector);
193 }
194
195 c.drawBitmap(buttonRec, null, boundsRecIcon, mButtonPaint);
196 }
197
Alexandre Lision40954dc2013-10-09 15:24:03 -0400198 @Override
199 public int getAction(float x, float y) {
200
Alexandre Lision5cd659e2013-10-29 13:18:23 -0400201 float relativeX = x - getDrawerBounds().left;
202 float relativeY = y - getDrawerBounds().top;
Alexandre Lision40954dc2013-10-09 15:24:03 -0400203
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400204 if (!getDrawerBounds().contains(x, y) && !getBounds().contains(x, y)) {
Alexandre Lision5cd659e2013-10-29 13:18:23 -0400205 return actions.OUT_OF_BOUNDS;
206 }
Alexandre Lision40954dc2013-10-09 15:24:03 -0400207
208 if (boundsHoldButton.contains(relativeX, relativeY)) {
209 Log.i("Bubble", "Holding");
210 return actions.HOLD;
211 }
212
Alexandre Lision1a682572013-11-01 11:21:17 -0400213 if (boundsRecButton.contains(relativeX, relativeY)) {
214 Log.i("Bubble", "Record");
215 return actions.RECORD;
216 }
Alexandre Lision40954dc2013-10-09 15:24:03 -0400217
Alexandre Lision68855472013-10-10 16:20:46 -0400218 if (boundsMicButton.contains(relativeX, relativeY)) {
Alexandre Lision40954dc2013-10-09 15:24:03 -0400219 Log.i("Bubble", "Muting");
220 return actions.MUTE;
221 }
222
Alexandre Lision68855472013-10-10 16:20:46 -0400223 if (boundsHangUpButton.contains(relativeX, relativeY)) {
Alexandre Lision40954dc2013-10-09 15:24:03 -0400224 Log.i("Bubble", "hangup");
225 return actions.HANGUP;
226 }
227
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400228 return actions.NOTHING;
Alexandre Lision40954dc2013-10-09 15:24:03 -0400229
230 }
231
232 }
233
234 @Override
235 public Bitmap getDrawerBitmap() {
236 return act.img;
237 }
238
239 @Override
240 public RectF getDrawerBounds() {
241 return act.bounds;
242 }
243
Alexandre Lision68855472013-10-10 16:20:46 -0400244 public void setConference(Conference c) {
245 associated_call = c;
Alexandre Lisiona9485b82013-10-25 10:00:57 -0400246 if (expanded) {
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400247 act.generateBitmap(actions.NOTHING);
Alexandre Lisiona9485b82013-10-25 10:00:57 -0400248 }
Alexandre Lisionee2494d2013-10-09 17:14:00 -0400249 }
250
251 @Override
Alexandre Lision68855472013-10-10 16:20:46 -0400252 public String getName() {
253 return mContext.getResources().getString(R.string.me);
254 }
255
256 @Override
257 public boolean callIDEquals(String call) {
258 return associated_call.getId().contentEquals(call);
259 }
260
261 @Override
262 public String getCallID() {
263 if (associated_call.hasMultipleParticipants())
264 return associated_call.getId();
265 else
266 return associated_call.getParticipants().get(0).getCallId();
267 }
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400268
Alexandre Lision68855472013-10-10 16:20:46 -0400269 @Override
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400270 public boolean isConference() {
Alexandre Lision68855472013-10-10 16:20:46 -0400271 return associated_call.hasMultipleParticipants();
Alexandre Lisionee2494d2013-10-09 17:14:00 -0400272 }
273
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400274 @Override
275 public boolean onDown(MotionEvent event) {
276 if (expanded) {
277 act.generateBitmap(act.getAction(event.getX(), event.getY()));
278 return false;
279 }
280
281 if (intersects(event.getX(), event.getY())) {
282 dragged = true;
283 last_drag = System.nanoTime();
284 setPos(event.getX(), event.getY());
285 target_scale = .8f;
286 return true;
287 }
288 return false;
289 }
Alexandre Lision40954dc2013-10-09 15:24:03 -0400290}