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; |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 8 | import android.graphics.Paint.Style; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 9 | import android.graphics.BitmapFactory; |
| 10 | import android.graphics.Canvas; |
| 11 | import android.graphics.Paint; |
| 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; |
| 15 | import android.widget.Toast; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 16 | |
| 17 | public class BubbleUser extends Bubble { |
| 18 | |
| 19 | public Conference associated_call; |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 20 | Bitmap buttonMic, buttonMicMuted, buttonHold, buttonUnhold, buttonRecord, buttonHangUp; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 21 | float expanded_radius; |
| 22 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 23 | public BubbleUser(Context context, CallContact m, Conference conf, float x, float y, float size) { |
| 24 | super(context, m, x, y, size); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 25 | isUser = true; |
| 26 | associated_call = conf; |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 27 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 28 | expanded_radius = (float) (size * 1.5); |
| 29 | |
| 30 | buttonMic = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_mic); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 31 | buttonMicMuted = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_mic_muted); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 32 | buttonHold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_pause_over_video); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 33 | buttonUnhold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_play_over_video); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 34 | // buttonRecord = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_); |
| 35 | buttonHangUp = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_end_call); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 36 | |
| 37 | setDrawer(new ActionDrawer(0, 0)); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 38 | } |
| 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 Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 62 | act.generateBitmap(actions.NOTHING); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 63 | |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public int getRadius() { |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 68 | if (expanded) |
Alexandre Lision | a9485b8 | 2013-10-25 10:00:57 -0400 | [diff] [blame] | 69 | return (int) (radius * density); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 70 | return (int) (radius * scale * density); |
| 71 | } |
| 72 | |
| 73 | public int getExpandedRadius() { |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 74 | return (int) (expanded_radius * density); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 75 | } |
| 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 Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 93 | // @Override |
| 94 | public Conference getConference() { |
| 95 | return associated_call; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | protected class ActionDrawer extends Bubble.ActionDrawer { |
| 99 | |
| 100 | RectF boundsHoldButton, boundsMicButton, boundsRecordButton, boundsHangUpButton; |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 101 | int wHang, hHang; |
| 102 | int wHold, hHold; |
| 103 | int wMic, hMic; |
| 104 | Paint mBackgroundPaint; |
| 105 | Paint mSelector; |
| 106 | Paint mButtonPaint; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 107 | |
| 108 | public ActionDrawer(int w, int h) { |
| 109 | super(w, h); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 110 | 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 Lision | 1888bf3 | 2013-10-31 09:51:41 -0400 | [diff] [blame] | 116 | mSelector.setColor(mContext.getResources().getColor(R.color.sfl_blue_9)); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 117 | |
| 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 Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | @Override |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 131 | public void generateBitmap(int action) { |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 132 | img = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 133 | Canvas c = new Canvas(img); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 134 | c.drawOval(new RectF(0, 0, mWidth, mHeight), mBackgroundPaint); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 135 | |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 136 | drawHangUp(c, action == actions.HANGUP); |
| 137 | drawHold(c, action == actions.HOLD); |
| 138 | drawMute(c, action == actions.MUTE); |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 139 | |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 140 | // boundsRecordButton = new RectF(mWidth / 2 - getRadius(), mHeight / 2 + getRadius(), mWidth / 2 + getRadius(), mHeight); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 141 | // c.drawBitmap(buttonRecord, null, boundsRecordButton, test4); |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 142 | |
| 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 Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 159 | } |
| 160 | |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 161 | 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 Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 200 | @Override |
| 201 | public int getAction(float x, float y) { |
| 202 | |
Alexandre Lision | 5cd659e | 2013-10-29 13:18:23 -0400 | [diff] [blame] | 203 | float relativeX = x - getDrawerBounds().left; |
| 204 | float relativeY = y - getDrawerBounds().top; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 205 | |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 206 | if (!getDrawerBounds().contains(x, y) && !getBounds().contains(x, y)) { |
Alexandre Lision | 5cd659e | 2013-10-29 13:18:23 -0400 | [diff] [blame] | 207 | return actions.OUT_OF_BOUNDS; |
| 208 | } |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 209 | |
| 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 Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 220 | if (boundsMicButton.contains(relativeX, relativeY)) { |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 221 | Log.i("Bubble", "Muting"); |
| 222 | return actions.MUTE; |
| 223 | } |
| 224 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 225 | if (boundsHangUpButton.contains(relativeX, relativeY)) { |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 226 | Log.i("Bubble", "hangup"); |
| 227 | return actions.HANGUP; |
| 228 | } |
| 229 | |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 230 | return actions.NOTHING; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 231 | |
| 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 Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 246 | public void setConference(Conference c) { |
| 247 | associated_call = c; |
Alexandre Lision | a9485b8 | 2013-10-25 10:00:57 -0400 | [diff] [blame] | 248 | if (expanded) { |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 249 | act.generateBitmap(actions.NOTHING); |
Alexandre Lision | a9485b8 | 2013-10-25 10:00:57 -0400 | [diff] [blame] | 250 | } |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | @Override |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 254 | 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 Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 270 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 271 | @Override |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 272 | public boolean isConference() { |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 273 | return associated_call.hasMultipleParticipants(); |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame] | 274 | } |
| 275 | |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 276 | @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 Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 292 | } |