blob: ff968c1a2dc4bd6207a175eb894dbc9921dcedc9 [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;
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -04008import android.graphics.Paint.Style;
Alexandre Lision40954dc2013-10-09 15:24:03 -04009import android.graphics.BitmapFactory;
10import android.graphics.Canvas;
11import android.graphics.Paint;
12import android.graphics.RectF;
13import android.util.Log;
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -040014import android.view.MotionEvent;
15import android.widget.Toast;
Alexandre Lision40954dc2013-10-09 15:24:03 -040016
17public class BubbleUser extends Bubble {
18
19 public Conference associated_call;
Alexandre Lision68855472013-10-10 16:20:46 -040020 Bitmap buttonMic, buttonMicMuted, buttonHold, buttonUnhold, buttonRecord, buttonHangUp;
Alexandre Lision40954dc2013-10-09 15:24:03 -040021 float expanded_radius;
22
Alexandre Lision68855472013-10-10 16:20:46 -040023 public BubbleUser(Context context, CallContact m, Conference conf, float x, float y, float size) {
24 super(context, m, x, y, size);
Alexandre Lision40954dc2013-10-09 15:24:03 -040025 isUser = true;
26 associated_call = conf;
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -040027
Alexandre Lision40954dc2013-10-09 15:24:03 -040028 expanded_radius = (float) (size * 1.5);
29
30 buttonMic = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_mic);
Alexandre Lision68855472013-10-10 16:20:46 -040031 buttonMicMuted = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_mic_muted);
Alexandre Lision40954dc2013-10-09 15:24:03 -040032 buttonHold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_pause_over_video);
Alexandre Lision68855472013-10-10 16:20:46 -040033 buttonUnhold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_play_over_video);
Alexandre Lision40954dc2013-10-09 15:24:03 -040034 // buttonRecord = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_);
35 buttonHangUp = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_end_call);
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -040036
37 setDrawer(new ActionDrawer(0, 0));
Alexandre Lision40954dc2013-10-09 15:24:03 -040038 }
39
40 @Override
41 public void set(float x, float y, float s) {
42 scale = s;
43 pos.x = x;
44 pos.y = y;
45 bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius());
46 if (!expanded) {
47 bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius());
48 } else {
49 bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius());
50 act.setBounds(pos.x - getExpandedRadius(), pos.y - getExpandedRadius(), pos.x + getExpandedRadius(), pos.y + getExpandedRadius());
51 }
52 }
53
54 @Override
55 public void expand(int width, int height) {
56
57 expanded = true;
58 generateBitmap();
59 setDrawer(new ActionDrawer((int) getExpandedRadius() * 2, (int) getExpandedRadius() * 2));
60
61 act.setBounds(pos.x - getExpandedRadius(), pos.y - getExpandedRadius(), pos.x + getExpandedRadius(), pos.y + getExpandedRadius());
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -040062 act.generateBitmap(actions.NOTHING);
Alexandre Lision40954dc2013-10-09 15:24:03 -040063
64 }
65
66 @Override
67 public int getRadius() {
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -040068 if (expanded)
Alexandre Lisiona9485b82013-10-25 10:00:57 -040069 return (int) (radius * density);
Alexandre Lision40954dc2013-10-09 15:24:03 -040070 return (int) (radius * scale * density);
71 }
72
73 public int getExpandedRadius() {
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -040074 return (int) (expanded_radius * density);
Alexandre Lision40954dc2013-10-09 15:24:03 -040075 }
76
77 @Override
78 public boolean getHoldStatus() {
79 if (associated_call.isOnHold())
80 return true;
81 else
82 return false;
83 }
84
85 @Override
86 public boolean getRecordStatus() {
87 if (associated_call.isRecording())
88 return true;
89 else
90 return false;
91 }
92
Alexandre Lision68855472013-10-10 16:20:46 -040093 // @Override
94 public Conference getConference() {
95 return associated_call;
Alexandre Lision40954dc2013-10-09 15:24:03 -040096 }
97
98 protected class ActionDrawer extends Bubble.ActionDrawer {
99
100 RectF boundsHoldButton, boundsMicButton, boundsRecordButton, boundsHangUpButton;
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400101 int wHang, hHang;
102 int wHold, hHold;
103 int wMic, hMic;
104 Paint mBackgroundPaint;
105 Paint mSelector;
106 Paint mButtonPaint;
Alexandre Lision40954dc2013-10-09 15:24:03 -0400107
108 public ActionDrawer(int w, int h) {
109 super(w, h);
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400110 mBackgroundPaint = new Paint();
111 mBackgroundPaint.setColor(mContext.getResources().getColor(R.color.sfl_blue_9));
112 mBackgroundPaint.setDither(true);
113
114 mSelector = new Paint();
115 mSelector.setStyle(Style.FILL);
Alexandre Lision1888bf32013-10-31 09:51:41 -0400116 mSelector.setColor(mContext.getResources().getColor(R.color.sfl_blue_9));
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400117
118 mButtonPaint = new Paint();
119
120 wHang = buttonHangUp.getWidth();
121 hHang = buttonHangUp.getHeight();
122
123 wHold = buttonHold.getWidth();
124 hHold = buttonHold.getHeight();
125
126 wMic = buttonMic.getWidth();
127 hMic = buttonMic.getHeight();
Alexandre Lision40954dc2013-10-09 15:24:03 -0400128 }
129
130 @Override
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400131 public void generateBitmap(int action) {
Alexandre Lision40954dc2013-10-09 15:24:03 -0400132 img = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888);
Alexandre Lision40954dc2013-10-09 15:24:03 -0400133 Canvas c = new Canvas(img);
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400134 c.drawOval(new RectF(0, 0, mWidth, mHeight), mBackgroundPaint);
Alexandre Lision40954dc2013-10-09 15:24:03 -0400135
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400136 drawHangUp(c, action == actions.HANGUP);
137 drawHold(c, action == actions.HOLD);
138 drawMute(c, action == actions.MUTE);
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400139
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400140 // boundsRecordButton = new RectF(mWidth / 2 - getRadius(), mHeight / 2 + getRadius(), mWidth / 2 + getRadius(), mHeight);
Alexandre Lision40954dc2013-10-09 15:24:03 -0400141 // c.drawBitmap(buttonRecord, null, boundsRecordButton, test4);
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400142
143 // float startAngle = ;
144 // float sweepAngle = 60;
145 //
146 // float startX = mHeight / 2;
147 // float startY = mWidth / 2;
148 //
149 // float angle = (float) ((startAngle + sweepAngle / 2) * Math.PI / 180);
150 // float stopX = (float) (startX + getRadius() * Math.cos(angle));
151 // float stopY = (float) (startY + getRadius() * Math.sin(angle));
152 //
153 // Toast.makeText(mContext, "startX:" + startX + " startY:" + startY, Toast.LENGTH_SHORT).show();
154 // Toast.makeText(mContext, "stopX:" + stopX + " stopY:" + stopY, Toast.LENGTH_SHORT).show();
155 //
156 // Paint mPaint = new Paint();
157 // mPaint.setColor(Color.RED);
158 // c.drawLine(startX, startY, stopX, stopY, mPaint);
Alexandre Lision40954dc2013-10-09 15:24:03 -0400159 }
160
Alexandre Lision8fdcf2b2013-10-30 16:06:51 -0400161 private void drawHangUp(Canvas c, boolean selected) {
162 boundsHangUpButton = new RectF(mWidth / 2 - getRadius(), 0, mWidth / 2 + getRadius(), mHeight / 2 - getRadius());
163
164 RectF boundsHangUpIcon = new RectF((int) boundsHangUpButton.centerX() - wHang / 2, (int) boundsHangUpButton.centerY() - hHang / 2,
165 (int) boundsHangUpButton.centerX() + wHang / 2, (int) boundsHangUpButton.centerY() + hHang / 2);
166
167 if (selected) {
168 c.drawCircle(boundsHangUpButton.centerX(), boundsHangUpButton.centerY(), boundsHangUpButton.width() / 2, mSelector);
169 }
170
171 c.drawBitmap(buttonHangUp, null, boundsHangUpIcon, mButtonPaint);
172 }
173
174 private void drawHold(Canvas c, boolean selected) {
175 boundsHoldButton = new RectF(0, mHeight / 2 - getRadius(), mWidth / 2 - getRadius(), mHeight / 2 + getRadius());
176 RectF boundsHoldIcon = new RectF((int) boundsHoldButton.centerX() - wHold / 2, (int) boundsHoldButton.centerY() - hHold / 2,
177 (int) boundsHoldButton.centerX() + wHold / 2, (int) boundsHoldButton.centerY() + hHold / 2);
178 if (selected) {
179 c.drawCircle(boundsHoldButton.centerX(), boundsHoldButton.centerY(), boundsHoldButton.width() / 2, mSelector);
180 }
181
182 if (associated_call.isOnHold()) {
183 c.drawBitmap(buttonUnhold, null, boundsHoldIcon, mButtonPaint);
184 } else {
185 c.drawBitmap(buttonHold, null, boundsHoldIcon, mButtonPaint);
186 }
187 }
188
189 private void drawMute(Canvas c, boolean selected) {
190 boundsMicButton = new RectF(mWidth / 2 + getRadius(), mHeight / 2 - getRadius(), mWidth, mHeight / 2 + getRadius());
191 RectF boundsMuteIcon = new RectF((int) boundsMicButton.centerX() - wMic / 2, (int) boundsMicButton.centerY() - hMic / 2,
192 (int) boundsMicButton.centerX() + wMic / 2, (int) boundsMicButton.centerY() + hMic / 2);
193 if (selected) {
194 c.drawCircle(boundsMicButton.centerX(), boundsMicButton.centerY(), boundsMicButton.width() / 2, mSelector);
195 }
196
197 c.drawBitmap(buttonMic, null, boundsMuteIcon, mButtonPaint);
198 }
199
Alexandre Lision40954dc2013-10-09 15:24:03 -0400200 @Override
201 public int getAction(float x, float y) {
202
Alexandre Lision5cd659e2013-10-29 13:18:23 -0400203 float relativeX = x - getDrawerBounds().left;
204 float relativeY = y - getDrawerBounds().top;
Alexandre Lision40954dc2013-10-09 15:24:03 -0400205
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400206 if (!getDrawerBounds().contains(x, y) && !getBounds().contains(x, y)) {
Alexandre Lision5cd659e2013-10-29 13:18:23 -0400207 return actions.OUT_OF_BOUNDS;
208 }
Alexandre Lision40954dc2013-10-09 15:24:03 -0400209
210 if (boundsHoldButton.contains(relativeX, relativeY)) {
211 Log.i("Bubble", "Holding");
212 return actions.HOLD;
213 }
214
215 // if (boundsRecordButton.contains(x, y)) {
216 // Log.i("Bubble", "Record");
217 // return actions.RECORD;
218 // }
219
Alexandre Lision68855472013-10-10 16:20:46 -0400220 if (boundsMicButton.contains(relativeX, relativeY)) {
Alexandre Lision40954dc2013-10-09 15:24:03 -0400221 Log.i("Bubble", "Muting");
222 return actions.MUTE;
223 }
224
Alexandre Lision68855472013-10-10 16:20:46 -0400225 if (boundsHangUpButton.contains(relativeX, relativeY)) {
Alexandre Lision40954dc2013-10-09 15:24:03 -0400226 Log.i("Bubble", "hangup");
227 return actions.HANGUP;
228 }
229
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400230 return actions.NOTHING;
Alexandre Lision40954dc2013-10-09 15:24:03 -0400231
232 }
233
234 }
235
236 @Override
237 public Bitmap getDrawerBitmap() {
238 return act.img;
239 }
240
241 @Override
242 public RectF getDrawerBounds() {
243 return act.bounds;
244 }
245
Alexandre Lision68855472013-10-10 16:20:46 -0400246 public void setConference(Conference c) {
247 associated_call = c;
Alexandre Lisiona9485b82013-10-25 10:00:57 -0400248 if (expanded) {
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400249 act.generateBitmap(actions.NOTHING);
Alexandre Lisiona9485b82013-10-25 10:00:57 -0400250 }
Alexandre Lisionee2494d2013-10-09 17:14:00 -0400251 }
252
253 @Override
Alexandre Lision68855472013-10-10 16:20:46 -0400254 public String getName() {
255 return mContext.getResources().getString(R.string.me);
256 }
257
258 @Override
259 public boolean callIDEquals(String call) {
260 return associated_call.getId().contentEquals(call);
261 }
262
263 @Override
264 public String getCallID() {
265 if (associated_call.hasMultipleParticipants())
266 return associated_call.getId();
267 else
268 return associated_call.getParticipants().get(0).getCallId();
269 }
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400270
Alexandre Lision68855472013-10-10 16:20:46 -0400271 @Override
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400272 public boolean isConference() {
Alexandre Lision68855472013-10-10 16:20:46 -0400273 return associated_call.hasMultipleParticipants();
Alexandre Lisionee2494d2013-10-09 17:14:00 -0400274 }
275
Alexandre Lisiond9c3f7f2013-10-30 15:20:55 -0400276 @Override
277 public boolean onDown(MotionEvent event) {
278 if (expanded) {
279 act.generateBitmap(act.getAction(event.getX(), event.getY()));
280 return false;
281 }
282
283 if (intersects(event.getX(), event.getY())) {
284 dragged = true;
285 last_drag = System.nanoTime();
286 setPos(event.getX(), event.getY());
287 target_scale = .8f;
288 return true;
289 }
290 return false;
291 }
Alexandre Lision40954dc2013-10-09 15:24:03 -0400292}