blob: cefc32ac141e197d56420c41ff138c14ee127297 [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;
11import android.graphics.RectF;
12import android.util.Log;
13
14public class BubbleUser extends Bubble {
15
16 public Conference associated_call;
Alexandre Lision68855472013-10-10 16:20:46 -040017 Bitmap buttonMic, buttonMicMuted, buttonHold, buttonUnhold, buttonRecord, buttonHangUp;
Alexandre Lision40954dc2013-10-09 15:24:03 -040018 float expanded_radius;
19
Alexandre Lision68855472013-10-10 16:20:46 -040020 public BubbleUser(Context context, CallContact m, Conference conf, float x, float y, float size) {
21 super(context, m, x, y, size);
Alexandre Lision40954dc2013-10-09 15:24:03 -040022 isUser = true;
23 associated_call = conf;
24 setDrawer(new ActionDrawer(0, 0));
25 expanded_radius = (float) (size * 1.5);
26
27 buttonMic = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_mic);
Alexandre Lision68855472013-10-10 16:20:46 -040028 buttonMicMuted = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_mic_muted);
Alexandre Lision40954dc2013-10-09 15:24:03 -040029 buttonHold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_pause_over_video);
Alexandre Lision68855472013-10-10 16:20:46 -040030 buttonUnhold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_play_over_video);
Alexandre Lision40954dc2013-10-09 15:24:03 -040031 // buttonRecord = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_);
32 buttonHangUp = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_end_call);
33 }
34
35 @Override
36 public void set(float x, float y, float s) {
37 scale = s;
38 pos.x = x;
39 pos.y = y;
40 bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius());
41 if (!expanded) {
42 bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius());
43 } else {
44 bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius());
45 act.setBounds(pos.x - getExpandedRadius(), pos.y - getExpandedRadius(), pos.x + getExpandedRadius(), pos.y + getExpandedRadius());
46 }
47 }
48
49 @Override
50 public void expand(int width, int height) {
51
52 expanded = true;
53 generateBitmap();
54 setDrawer(new ActionDrawer((int) getExpandedRadius() * 2, (int) getExpandedRadius() * 2));
55
56 act.setBounds(pos.x - getExpandedRadius(), pos.y - getExpandedRadius(), pos.x + getExpandedRadius(), pos.y + getExpandedRadius());
57 act.generateBitmap();
58
59 }
60
61 @Override
62 public int getRadius() {
63 return (int) (radius * scale * density);
64 }
65
66 public int getExpandedRadius() {
67 return (int) (expanded_radius * scale * density);
68 }
69
70 @Override
71 public boolean getHoldStatus() {
72 if (associated_call.isOnHold())
73 return true;
74 else
75 return false;
76 }
77
78 @Override
79 public boolean getRecordStatus() {
80 if (associated_call.isRecording())
81 return true;
82 else
83 return false;
84 }
85
Alexandre Lision68855472013-10-10 16:20:46 -040086 // @Override
87 public Conference getConference() {
88 return associated_call;
Alexandre Lision40954dc2013-10-09 15:24:03 -040089 }
90
91 protected class ActionDrawer extends Bubble.ActionDrawer {
92
93 RectF boundsHoldButton, boundsMicButton, boundsRecordButton, boundsHangUpButton;
94
95 public ActionDrawer(int w, int h) {
96 super(w, h);
97 }
98
99 @Override
100 public void generateBitmap() {
101 img = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888);
102 Paint paint = new Paint();
103 paint.setColor(mContext.getResources().getColor(R.color.sfl_action_blue));
104 paint.setDither(true);
105 Canvas c = new Canvas(img);
106 c.drawOval(new RectF(0, 0, mWidth, mHeight), paint);
Alexandre Lision68855472013-10-10 16:20:46 -0400107 int wHang, hHang;
108 int wHold, hHold;
109 int wMic, hMic;
Alexandre Lision40954dc2013-10-09 15:24:03 -0400110
111 Paint test4 = new Paint();
112 boundsHangUpButton = new RectF(mWidth / 2 - getRadius(), 0, mWidth / 2 + getRadius(), mHeight / 2 - getRadius());
Alexandre Lision68855472013-10-10 16:20:46 -0400113 wHang = buttonHangUp.getWidth();
114 hHang = buttonHangUp.getHeight();
115 c.drawBitmap(buttonHangUp, null,
116 new RectF((int) boundsHangUpButton.centerX() - wHang / 2, (int) boundsHangUpButton.centerY() - hHang / 2,
117 (int) boundsHangUpButton.centerX() + wHang / 2, (int) boundsHangUpButton.centerY() + hHang / 2), test4);
118 // c.drawBitmap(buttonHangUp, null, boundsHangUpButton, test4);
Alexandre Lision40954dc2013-10-09 15:24:03 -0400119
120 boundsHoldButton = new RectF(0, mHeight / 2 - getRadius(), mWidth / 2 - getRadius(), mHeight / 2 + getRadius());
Alexandre Lision68855472013-10-10 16:20:46 -0400121 // c.drawBitmap(buttonHold, null, boundsHoldButton, test4);
Alexandre Lision40954dc2013-10-09 15:24:03 -0400122
Alexandre Lision68855472013-10-10 16:20:46 -0400123 wHold = buttonHold.getWidth();
124 hHold = buttonHold.getHeight();
125 if (associated_call.isOnHold()) {
126 c.drawBitmap(buttonUnhold, null, new RectF((int) boundsHoldButton.centerX() - wHold / 2,
127 (int) boundsHoldButton.centerY() - hHold / 2, (int) boundsHoldButton.centerX() + wHold / 2, (int) boundsHoldButton.centerY()
128 + hHold / 2), test4);
129 } else {
130 c.drawBitmap(buttonHold, null, new RectF((int) boundsHoldButton.centerX() - wHold / 2, (int) boundsHoldButton.centerY() - hHold / 2,
131 (int) boundsHoldButton.centerX() + wHold / 2, (int) boundsHoldButton.centerY() + hHold / 2), test4);
132 }
133
134 wMic = buttonMic.getWidth();
135 hMic = buttonMic.getHeight();
Alexandre Lision40954dc2013-10-09 15:24:03 -0400136 boundsMicButton = new RectF(mWidth / 2 + getRadius(), mHeight / 2 - getRadius(), mWidth, mHeight / 2 + getRadius());
Alexandre Lision68855472013-10-10 16:20:46 -0400137 c.drawBitmap(buttonMic, null, new RectF((int) boundsMicButton.centerX() - wMic / 2, (int) boundsMicButton.centerY() - hMic / 2,
138 (int) boundsMicButton.centerX() + wMic / 2, (int) boundsMicButton.centerY() + hMic / 2), test4);
139 // c.drawBitmap(buttonMic, null, boundsMicButton, test4);
Alexandre Lision40954dc2013-10-09 15:24:03 -0400140 // //
Alexandre Lision68855472013-10-10 16:20:46 -0400141 boundsRecordButton = new RectF(mWidth / 2 - getRadius(), mHeight / 2 + getRadius(), mWidth / 2 + getRadius(), mHeight);
Alexandre Lision40954dc2013-10-09 15:24:03 -0400142 // c.drawBitmap(buttonRecord, null, boundsRecordButton, test4);
143 }
144
145 @Override
146 public int getAction(float x, float y) {
147
148 float relativeX = x - getBounds().left;
149 float relativeY = y - getBounds().top;
150
151 Log.i("Bubble", "relativeX:" + relativeX);
152 Log.i("Bubble", "relativeY:" + relativeY);
153
154 Log.i("Bubble", "pos.x:" + pos.x);
155 Log.i("Bubble", "pos.y:" + pos.y);
156 //
157 // Log.i("Bubble", getBounds().toShortString());
158 //
159 Log.i("boundsHoldButton", boundsHoldButton.toShortString());
160 Log.i("boundsMicButton", boundsMicButton.toShortString());
161 Log.i("boundsHangUpButton", boundsHangUpButton.toShortString());
162
163 if (boundsHoldButton.contains(relativeX, relativeY)) {
164 Log.i("Bubble", "Holding");
165 return actions.HOLD;
166 }
167
168 // if (boundsRecordButton.contains(x, y)) {
169 // Log.i("Bubble", "Record");
170 // return actions.RECORD;
171 // }
172
Alexandre Lision68855472013-10-10 16:20:46 -0400173 if (boundsMicButton.contains(relativeX, relativeY)) {
Alexandre Lision40954dc2013-10-09 15:24:03 -0400174 Log.i("Bubble", "Muting");
175 return actions.MUTE;
176 }
177
Alexandre Lision68855472013-10-10 16:20:46 -0400178 if (boundsHangUpButton.contains(relativeX, relativeY)) {
Alexandre Lision40954dc2013-10-09 15:24:03 -0400179 Log.i("Bubble", "hangup");
180 return actions.HANGUP;
181 }
182
183 return 0;
184
185 }
186
187 }
188
189 @Override
190 public Bitmap getDrawerBitmap() {
191 return act.img;
192 }
193
194 @Override
195 public RectF getDrawerBounds() {
196 return act.bounds;
197 }
198
Alexandre Lision68855472013-10-10 16:20:46 -0400199 public void setConference(Conference c) {
200 associated_call = c;
Alexandre Lisionee2494d2013-10-09 17:14:00 -0400201 }
202
203 @Override
Alexandre Lision68855472013-10-10 16:20:46 -0400204 public String getName() {
205 return mContext.getResources().getString(R.string.me);
206 }
207
208 @Override
209 public boolean callIDEquals(String call) {
210 return associated_call.getId().contentEquals(call);
211 }
212
213 @Override
214 public String getCallID() {
215 if (associated_call.hasMultipleParticipants())
216 return associated_call.getId();
217 else
218 return associated_call.getParticipants().get(0).getCallId();
219 }
220
221 @Override
222 public boolean isConference(){
223 return associated_call.hasMultipleParticipants();
Alexandre Lisionee2494d2013-10-09 17:14:00 -0400224 }
225
Alexandre Lision40954dc2013-10-09 15:24:03 -0400226}