Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 1 | /* |
Alexandre Lision | c1024c0 | 2014-01-06 11:12:53 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. |
Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 3 | * |
| 4 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | * |
| 20 | * Additional permission under GNU GPL version 3 section 7: |
| 21 | * |
| 22 | * If you modify this program, or any covered work, by linking or |
| 23 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 24 | * modified version of that library), containing parts covered by the |
| 25 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 26 | * grants you additional permission to convey the resulting work. |
| 27 | * Corresponding Source for a non-source form of such a combination |
| 28 | * shall include the source code for the parts of OpenSSL used as well |
| 29 | * as that of the covered work. |
| 30 | */ |
| 31 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 32 | package org.sflphone.model; |
| 33 | |
| 34 | import org.sflphone.R; |
| 35 | |
| 36 | import android.content.Context; |
| 37 | import android.graphics.Bitmap; |
| 38 | import android.graphics.Bitmap.Config; |
| 39 | import android.graphics.BitmapFactory; |
| 40 | import android.graphics.Canvas; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 41 | import android.graphics.RectF; |
| 42 | import android.util.Log; |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 43 | import android.view.MotionEvent; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 44 | |
| 45 | public class BubbleUser extends Bubble { |
| 46 | |
| 47 | public Conference associated_call; |
Alexandre Lision | 1a68257 | 2013-11-01 11:21:17 -0400 | [diff] [blame] | 48 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 49 | float expanded_radius; |
| 50 | |
Alexandre Lision | c9fca9e | 2013-11-08 15:21:18 -0500 | [diff] [blame] | 51 | private boolean mMuted; |
| 52 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 53 | public BubbleUser(Context context, CallContact m, Conference conf, float x, float y, float size) { |
| 54 | super(context, m, x, y, size); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 55 | isUser = true; |
| 56 | associated_call = conf; |
Alexandre Lision | c9fca9e | 2013-11-08 15:21:18 -0500 | [diff] [blame] | 57 | mMuted = false; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 58 | expanded_radius = (float) (size * 1.5); |
| 59 | |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 60 | setDrawer(new ActionDrawer(0, 0)); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public void set(float x, float y, float s) { |
| 65 | scale = s; |
| 66 | pos.x = x; |
| 67 | pos.y = y; |
| 68 | bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius()); |
| 69 | if (!expanded) { |
| 70 | bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius()); |
| 71 | } else { |
| 72 | bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius()); |
| 73 | act.setBounds(pos.x - getExpandedRadius(), pos.y - getExpandedRadius(), pos.x + getExpandedRadius(), pos.y + getExpandedRadius()); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public void expand(int width, int height) { |
| 79 | |
| 80 | expanded = true; |
| 81 | generateBitmap(); |
| 82 | setDrawer(new ActionDrawer((int) getExpandedRadius() * 2, (int) getExpandedRadius() * 2)); |
| 83 | |
| 84 | 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] | 85 | act.generateBitmap(actions.NOTHING); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 86 | |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public int getRadius() { |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 91 | if (expanded) |
Alexandre Lision | a9485b8 | 2013-10-25 10:00:57 -0400 | [diff] [blame] | 92 | return (int) (radius * density); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 93 | return (int) (radius * scale * density); |
| 94 | } |
| 95 | |
| 96 | public int getExpandedRadius() { |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 97 | return (int) (expanded_radius * density); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public boolean getHoldStatus() { |
| 102 | if (associated_call.isOnHold()) |
| 103 | return true; |
| 104 | else |
| 105 | return false; |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public boolean getRecordStatus() { |
| 110 | if (associated_call.isRecording()) |
| 111 | return true; |
| 112 | else |
| 113 | return false; |
| 114 | } |
| 115 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 116 | // @Override |
| 117 | public Conference getConference() { |
| 118 | return associated_call; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | protected class ActionDrawer extends Bubble.ActionDrawer { |
| 122 | |
Alexandre Lision | 1a68257 | 2013-11-01 11:21:17 -0400 | [diff] [blame] | 123 | RectF boundsHoldButton, boundsMicButton, boundsRecButton, boundsHangUpButton; |
| 124 | |
| 125 | Bitmap buttonMic, buttonMicMuted, buttonHold, buttonUnhold, buttonRec, buttonHangUp; |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 126 | int wHang, hHang; |
| 127 | int wHold, hHold; |
| 128 | int wMic, hMic; |
Alexandre Lision | 1a68257 | 2013-11-01 11:21:17 -0400 | [diff] [blame] | 129 | int wRec, hRec; |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 130 | |
| 131 | float delta; |
| 132 | |
| 133 | private RectF globals; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 134 | |
| 135 | public ActionDrawer(int w, int h) { |
| 136 | super(w, h); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 137 | |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 138 | delta = (float) (w / 2 * Math.cos(Math.toRadians(45d))); |
| 139 | globals = new RectF(0, 0, mWidth, mHeight); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 140 | |
Alexandre Lision | 1a68257 | 2013-11-01 11:21:17 -0400 | [diff] [blame] | 141 | buttonMic = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_mic); |
| 142 | buttonMicMuted = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_mic_muted); |
| 143 | buttonHold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_pause_over_video); |
| 144 | buttonUnhold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_play_over_video); |
| 145 | buttonRec = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.recordpressed); |
| 146 | buttonHangUp = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_end_call); |
| 147 | |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 148 | wHang = buttonHangUp.getWidth(); |
| 149 | hHang = buttonHangUp.getHeight(); |
| 150 | |
| 151 | wHold = buttonHold.getWidth(); |
| 152 | hHold = buttonHold.getHeight(); |
| 153 | |
| 154 | wMic = buttonMic.getWidth(); |
| 155 | hMic = buttonMic.getHeight(); |
Alexandre Lision | 1a68257 | 2013-11-01 11:21:17 -0400 | [diff] [blame] | 156 | |
| 157 | wRec = buttonRec.getWidth(); |
| 158 | hRec = buttonRec.getHeight(); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | @Override |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 162 | public void generateBitmap(int action) { |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 163 | img = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 164 | Canvas c = new Canvas(img); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 165 | c.drawOval(new RectF(0, 0, mWidth, mHeight), mBackgroundPaint); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 166 | |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 167 | drawHangUp(c, action == actions.HANGUP); |
| 168 | drawHold(c, action == actions.HOLD); |
| 169 | drawMute(c, action == actions.MUTE); |
Alexandre Lision | 1a68257 | 2013-11-01 11:21:17 -0400 | [diff] [blame] | 170 | drawRec(c, action == actions.RECORD); |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 171 | |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 172 | c.drawLine(mWidth / 2 - delta, mHeight / 2 - delta, mWidth / 2 + delta, mHeight / 2 + delta, mLines); |
| 173 | c.drawLine(mWidth / 2 - delta, mHeight / 2 + delta, mWidth / 2 + delta, mHeight / 2 - delta, mLines); |
| 174 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 175 | } |
| 176 | |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 177 | private void drawHangUp(Canvas c, boolean selected) { |
| 178 | boundsHangUpButton = new RectF(mWidth / 2 - getRadius(), 0, mWidth / 2 + getRadius(), mHeight / 2 - getRadius()); |
| 179 | |
| 180 | RectF boundsHangUpIcon = new RectF((int) boundsHangUpButton.centerX() - wHang / 2, (int) boundsHangUpButton.centerY() - hHang / 2, |
| 181 | (int) boundsHangUpButton.centerX() + wHang / 2, (int) boundsHangUpButton.centerY() + hHang / 2); |
| 182 | |
| 183 | if (selected) { |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 184 | c.drawArc(globals, 225, 90, true, mSelector); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | c.drawBitmap(buttonHangUp, null, boundsHangUpIcon, mButtonPaint); |
| 188 | } |
| 189 | |
| 190 | private void drawHold(Canvas c, boolean selected) { |
| 191 | boundsHoldButton = new RectF(0, mHeight / 2 - getRadius(), mWidth / 2 - getRadius(), mHeight / 2 + getRadius()); |
| 192 | RectF boundsHoldIcon = new RectF((int) boundsHoldButton.centerX() - wHold / 2, (int) boundsHoldButton.centerY() - hHold / 2, |
| 193 | (int) boundsHoldButton.centerX() + wHold / 2, (int) boundsHoldButton.centerY() + hHold / 2); |
| 194 | if (selected) { |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 195 | c.drawArc(globals, 135, 90, true, mSelector); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | if (associated_call.isOnHold()) { |
| 199 | c.drawBitmap(buttonUnhold, null, boundsHoldIcon, mButtonPaint); |
| 200 | } else { |
| 201 | c.drawBitmap(buttonHold, null, boundsHoldIcon, mButtonPaint); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | private void drawMute(Canvas c, boolean selected) { |
| 206 | boundsMicButton = new RectF(mWidth / 2 + getRadius(), mHeight / 2 - getRadius(), mWidth, mHeight / 2 + getRadius()); |
| 207 | RectF boundsMuteIcon = new RectF((int) boundsMicButton.centerX() - wMic / 2, (int) boundsMicButton.centerY() - hMic / 2, |
| 208 | (int) boundsMicButton.centerX() + wMic / 2, (int) boundsMicButton.centerY() + hMic / 2); |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 209 | if (selected || mMuted) { |
| 210 | c.drawArc(globals, -45, 90, true, mSelector); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | c.drawBitmap(buttonMic, null, boundsMuteIcon, mButtonPaint); |
| 214 | } |
| 215 | |
Alexandre Lision | 1a68257 | 2013-11-01 11:21:17 -0400 | [diff] [blame] | 216 | private void drawRec(Canvas c, boolean selected) { |
| 217 | boundsRecButton = new RectF(mWidth / 2 - getRadius(), mHeight / 2 + getRadius(), mWidth / 2 + getRadius(), mHeight); |
| 218 | RectF boundsRecIcon = new RectF((int) boundsRecButton.centerX() - wRec / 2, (int) boundsRecButton.centerY() - hRec / 2, |
| 219 | (int) boundsRecButton.centerX() + wRec / 2, (int) boundsRecButton.centerY() + hMic / 2); |
| 220 | if (selected || associated_call.isRecording()) { |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 221 | c.drawArc(globals, 45, 90, true, mSelector); |
Alexandre Lision | 1a68257 | 2013-11-01 11:21:17 -0400 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | c.drawBitmap(buttonRec, null, boundsRecIcon, mButtonPaint); |
| 225 | } |
| 226 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 227 | @Override |
| 228 | public int getAction(float x, float y) { |
| 229 | |
Alexandre Lision | 5cd659e | 2013-10-29 13:18:23 -0400 | [diff] [blame] | 230 | float relativeX = x - getDrawerBounds().left; |
| 231 | float relativeY = y - getDrawerBounds().top; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 232 | |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 233 | if (!getDrawerBounds().contains(x, y) && !getBounds().contains(x, y)) { |
Alexandre Lision | 5cd659e | 2013-10-29 13:18:23 -0400 | [diff] [blame] | 234 | return actions.OUT_OF_BOUNDS; |
| 235 | } |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 236 | |
| 237 | if (boundsHoldButton.contains(relativeX, relativeY)) { |
| 238 | Log.i("Bubble", "Holding"); |
| 239 | return actions.HOLD; |
| 240 | } |
| 241 | |
Alexandre Lision | 1a68257 | 2013-11-01 11:21:17 -0400 | [diff] [blame] | 242 | if (boundsRecButton.contains(relativeX, relativeY)) { |
| 243 | Log.i("Bubble", "Record"); |
| 244 | return actions.RECORD; |
| 245 | } |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 246 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 247 | if (boundsMicButton.contains(relativeX, relativeY)) { |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 248 | Log.i("Bubble", "Muting"); |
| 249 | return actions.MUTE; |
| 250 | } |
| 251 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 252 | if (boundsHangUpButton.contains(relativeX, relativeY)) { |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 253 | Log.i("Bubble", "hangup"); |
| 254 | return actions.HANGUP; |
| 255 | } |
| 256 | |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 257 | return actions.NOTHING; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 258 | |
| 259 | } |
| 260 | |
| 261 | } |
| 262 | |
| 263 | @Override |
| 264 | public Bitmap getDrawerBitmap() { |
| 265 | return act.img; |
| 266 | } |
| 267 | |
| 268 | @Override |
| 269 | public RectF getDrawerBounds() { |
| 270 | return act.bounds; |
| 271 | } |
| 272 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 273 | public void setConference(Conference c) { |
| 274 | associated_call = c; |
Alexandre Lision | a9485b8 | 2013-10-25 10:00:57 -0400 | [diff] [blame] | 275 | if (expanded) { |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 276 | act.generateBitmap(actions.NOTHING); |
Alexandre Lision | a9485b8 | 2013-10-25 10:00:57 -0400 | [diff] [blame] | 277 | } |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | @Override |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 281 | public String getName() { |
| 282 | return mContext.getResources().getString(R.string.me); |
| 283 | } |
| 284 | |
| 285 | @Override |
| 286 | public boolean callIDEquals(String call) { |
| 287 | return associated_call.getId().contentEquals(call); |
| 288 | } |
| 289 | |
| 290 | @Override |
| 291 | public String getCallID() { |
| 292 | if (associated_call.hasMultipleParticipants()) |
| 293 | return associated_call.getId(); |
| 294 | else |
| 295 | return associated_call.getParticipants().get(0).getCallId(); |
| 296 | } |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 297 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 298 | @Override |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 299 | public boolean isConference() { |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 300 | return associated_call.hasMultipleParticipants(); |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame] | 301 | } |
| 302 | |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 303 | @Override |
| 304 | public boolean onDown(MotionEvent event) { |
| 305 | if (expanded) { |
| 306 | act.generateBitmap(act.getAction(event.getX(), event.getY())); |
| 307 | return false; |
| 308 | } |
| 309 | |
| 310 | if (intersects(event.getX(), event.getY())) { |
| 311 | dragged = true; |
| 312 | last_drag = System.nanoTime(); |
| 313 | setPos(event.getX(), event.getY()); |
| 314 | target_scale = .8f; |
| 315 | return true; |
| 316 | } |
| 317 | return false; |
| 318 | } |
Alexandre Lision | c9fca9e | 2013-11-08 15:21:18 -0500 | [diff] [blame] | 319 | |
| 320 | public boolean getMute() { |
| 321 | return mMuted; |
| 322 | } |
| 323 | |
| 324 | public void toggleMute() { |
| 325 | mMuted = !mMuted; |
| 326 | act.generateBitmap(Bubble.actions.NOTHING); |
| 327 | |
| 328 | } |
| 329 | |
| 330 | public void setMute(boolean captureMuted) { |
| 331 | mMuted = captureMuted; |
Alexandre Lision | c9fca9e | 2013-11-08 15:21:18 -0500 | [diff] [blame] | 332 | } |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 333 | } |