Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 1 | package org.sflphone.model; |
| 2 | |
| 3 | import org.sflphone.R; |
| 4 | |
| 5 | import android.content.Context; |
| 6 | import android.graphics.Bitmap; |
| 7 | import android.graphics.Bitmap.Config; |
| 8 | import android.graphics.BitmapFactory; |
| 9 | import android.graphics.Canvas; |
| 10 | import android.graphics.Paint; |
Alexandre Lision | 1a68257 | 2013-11-01 11:21:17 -0400 | [diff] [blame] | 11 | import android.graphics.Paint.Style; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 12 | import android.graphics.RectF; |
| 13 | import android.util.Log; |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 14 | import android.view.MotionEvent; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 15 | |
| 16 | public class BubbleUser extends Bubble { |
| 17 | |
| 18 | public Conference associated_call; |
Alexandre Lision | 1a68257 | 2013-11-01 11:21:17 -0400 | [diff] [blame] | 19 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 20 | float expanded_radius; |
| 21 | |
Alexandre Lision | c9fca9e | 2013-11-08 15:21:18 -0500 | [diff] [blame] | 22 | private boolean mMuted; |
| 23 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 24 | public BubbleUser(Context context, CallContact m, Conference conf, float x, float y, float size) { |
| 25 | super(context, m, x, y, size); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 26 | isUser = true; |
| 27 | associated_call = conf; |
Alexandre Lision | c9fca9e | 2013-11-08 15:21:18 -0500 | [diff] [blame] | 28 | mMuted = false; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 29 | expanded_radius = (float) (size * 1.5); |
| 30 | |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 31 | setDrawer(new ActionDrawer(0, 0)); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | @Override |
| 35 | public void set(float x, float y, float s) { |
| 36 | scale = s; |
| 37 | pos.x = x; |
| 38 | pos.y = y; |
| 39 | bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius()); |
| 40 | if (!expanded) { |
| 41 | bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius()); |
| 42 | } else { |
| 43 | bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius()); |
| 44 | act.setBounds(pos.x - getExpandedRadius(), pos.y - getExpandedRadius(), pos.x + getExpandedRadius(), pos.y + getExpandedRadius()); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public void expand(int width, int height) { |
| 50 | |
| 51 | expanded = true; |
| 52 | generateBitmap(); |
| 53 | setDrawer(new ActionDrawer((int) getExpandedRadius() * 2, (int) getExpandedRadius() * 2)); |
| 54 | |
| 55 | act.setBounds(pos.x - getExpandedRadius(), pos.y - getExpandedRadius(), pos.x + getExpandedRadius(), pos.y + getExpandedRadius()); |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 56 | act.generateBitmap(actions.NOTHING); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 57 | |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public int getRadius() { |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 62 | if (expanded) |
Alexandre Lision | a9485b8 | 2013-10-25 10:00:57 -0400 | [diff] [blame] | 63 | return (int) (radius * density); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 64 | return (int) (radius * scale * density); |
| 65 | } |
| 66 | |
| 67 | public int getExpandedRadius() { |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 68 | return (int) (expanded_radius * density); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public boolean getHoldStatus() { |
| 73 | if (associated_call.isOnHold()) |
| 74 | return true; |
| 75 | else |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public boolean getRecordStatus() { |
| 81 | if (associated_call.isRecording()) |
| 82 | return true; |
| 83 | else |
| 84 | return false; |
| 85 | } |
| 86 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 87 | // @Override |
| 88 | public Conference getConference() { |
| 89 | return associated_call; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | protected class ActionDrawer extends Bubble.ActionDrawer { |
| 93 | |
Alexandre Lision | 1a68257 | 2013-11-01 11:21:17 -0400 | [diff] [blame] | 94 | RectF boundsHoldButton, boundsMicButton, boundsRecButton, boundsHangUpButton; |
| 95 | |
| 96 | Bitmap buttonMic, buttonMicMuted, buttonHold, buttonUnhold, buttonRec, buttonHangUp; |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 97 | int wHang, hHang; |
| 98 | int wHold, hHold; |
| 99 | int wMic, hMic; |
Alexandre Lision | 1a68257 | 2013-11-01 11:21:17 -0400 | [diff] [blame] | 100 | int wRec, hRec; |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 101 | |
| 102 | float delta; |
| 103 | |
| 104 | private RectF globals; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 105 | |
| 106 | public ActionDrawer(int w, int h) { |
| 107 | super(w, h); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 108 | |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 109 | delta = (float) (w / 2 * Math.cos(Math.toRadians(45d))); |
| 110 | globals = new RectF(0, 0, mWidth, mHeight); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 111 | |
Alexandre Lision | 1a68257 | 2013-11-01 11:21:17 -0400 | [diff] [blame] | 112 | buttonMic = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_mic); |
| 113 | buttonMicMuted = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_mic_muted); |
| 114 | buttonHold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_pause_over_video); |
| 115 | buttonUnhold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_play_over_video); |
| 116 | buttonRec = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.recordpressed); |
| 117 | buttonHangUp = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_end_call); |
| 118 | |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 119 | wHang = buttonHangUp.getWidth(); |
| 120 | hHang = buttonHangUp.getHeight(); |
| 121 | |
| 122 | wHold = buttonHold.getWidth(); |
| 123 | hHold = buttonHold.getHeight(); |
| 124 | |
| 125 | wMic = buttonMic.getWidth(); |
| 126 | hMic = buttonMic.getHeight(); |
Alexandre Lision | 1a68257 | 2013-11-01 11:21:17 -0400 | [diff] [blame] | 127 | |
| 128 | wRec = buttonRec.getWidth(); |
| 129 | hRec = buttonRec.getHeight(); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | @Override |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 133 | public void generateBitmap(int action) { |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 134 | img = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 135 | Canvas c = new Canvas(img); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 136 | c.drawOval(new RectF(0, 0, mWidth, mHeight), mBackgroundPaint); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 137 | |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 138 | drawHangUp(c, action == actions.HANGUP); |
| 139 | drawHold(c, action == actions.HOLD); |
| 140 | drawMute(c, action == actions.MUTE); |
Alexandre Lision | 1a68257 | 2013-11-01 11:21:17 -0400 | [diff] [blame] | 141 | drawRec(c, action == actions.RECORD); |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 142 | |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 143 | c.drawLine(mWidth / 2 - delta, mHeight / 2 - delta, mWidth / 2 + delta, mHeight / 2 + delta, mLines); |
| 144 | c.drawLine(mWidth / 2 - delta, mHeight / 2 + delta, mWidth / 2 + delta, mHeight / 2 - delta, mLines); |
| 145 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 146 | } |
| 147 | |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 148 | 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) { |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 155 | c.drawArc(globals, 225, 90, true, mSelector); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 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) { |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 166 | c.drawArc(globals, 135, 90, true, mSelector); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 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); |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 180 | if (selected || mMuted) { |
| 181 | c.drawArc(globals, -45, 90, true, mSelector); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | c.drawBitmap(buttonMic, null, boundsMuteIcon, mButtonPaint); |
| 185 | } |
| 186 | |
Alexandre Lision | 1a68257 | 2013-11-01 11:21:17 -0400 | [diff] [blame] | 187 | 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()) { |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 192 | c.drawArc(globals, 45, 90, true, mSelector); |
Alexandre Lision | 1a68257 | 2013-11-01 11:21:17 -0400 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | c.drawBitmap(buttonRec, null, boundsRecIcon, mButtonPaint); |
| 196 | } |
| 197 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 198 | @Override |
| 199 | public int getAction(float x, float y) { |
| 200 | |
Alexandre Lision | 5cd659e | 2013-10-29 13:18:23 -0400 | [diff] [blame] | 201 | float relativeX = x - getDrawerBounds().left; |
| 202 | float relativeY = y - getDrawerBounds().top; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 203 | |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 204 | if (!getDrawerBounds().contains(x, y) && !getBounds().contains(x, y)) { |
Alexandre Lision | 5cd659e | 2013-10-29 13:18:23 -0400 | [diff] [blame] | 205 | return actions.OUT_OF_BOUNDS; |
| 206 | } |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 207 | |
| 208 | if (boundsHoldButton.contains(relativeX, relativeY)) { |
| 209 | Log.i("Bubble", "Holding"); |
| 210 | return actions.HOLD; |
| 211 | } |
| 212 | |
Alexandre Lision | 1a68257 | 2013-11-01 11:21:17 -0400 | [diff] [blame] | 213 | if (boundsRecButton.contains(relativeX, relativeY)) { |
| 214 | Log.i("Bubble", "Record"); |
| 215 | return actions.RECORD; |
| 216 | } |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 217 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 218 | if (boundsMicButton.contains(relativeX, relativeY)) { |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 219 | Log.i("Bubble", "Muting"); |
| 220 | return actions.MUTE; |
| 221 | } |
| 222 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 223 | if (boundsHangUpButton.contains(relativeX, relativeY)) { |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 224 | Log.i("Bubble", "hangup"); |
| 225 | return actions.HANGUP; |
| 226 | } |
| 227 | |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 228 | return actions.NOTHING; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 229 | |
| 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 Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 244 | public void setConference(Conference c) { |
| 245 | associated_call = c; |
Alexandre Lision | a9485b8 | 2013-10-25 10:00:57 -0400 | [diff] [blame] | 246 | if (expanded) { |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 247 | act.generateBitmap(actions.NOTHING); |
Alexandre Lision | a9485b8 | 2013-10-25 10:00:57 -0400 | [diff] [blame] | 248 | } |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | @Override |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 252 | 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 Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 268 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 269 | @Override |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 270 | public boolean isConference() { |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 271 | return associated_call.hasMultipleParticipants(); |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame] | 272 | } |
| 273 | |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 274 | @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 Lision | c9fca9e | 2013-11-08 15:21:18 -0500 | [diff] [blame] | 290 | |
| 291 | public boolean getMute() { |
| 292 | return mMuted; |
| 293 | } |
| 294 | |
| 295 | public void toggleMute() { |
| 296 | mMuted = !mMuted; |
| 297 | act.generateBitmap(Bubble.actions.NOTHING); |
| 298 | |
| 299 | } |
| 300 | |
| 301 | public void setMute(boolean captureMuted) { |
| 302 | mMuted = captureMuted; |
| 303 | |
| 304 | } |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 305 | } |