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; |
| 41 | import android.graphics.Paint; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 42 | import android.graphics.RectF; |
| 43 | import android.util.Log; |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 44 | import android.view.MotionEvent; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 45 | |
| 46 | public class BubbleContact extends Bubble { |
| 47 | |
| 48 | public SipCall associated_call; |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame] | 49 | Bitmap buttonMsg, buttonUnhold, buttonHold, buttonTransfer, buttonHangUp; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 50 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 51 | public interface drawerPosition { |
| 52 | int UNDEFINED = -1; |
| 53 | int TOP = 0; |
| 54 | int RIGHT = 1; |
| 55 | int BOTTOM = 2; |
| 56 | int LEFT = 3; |
| 57 | } |
| 58 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 59 | public BubbleContact(Context context, SipCall call, float x, float y, float size) { |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 60 | super(context, call.getmContact(), x, y, size); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 61 | associated_call = call; |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 62 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 63 | buttonMsg = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_chat); |
| 64 | buttonHold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_pause_over_video); |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame] | 65 | buttonUnhold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_play_over_video); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 66 | buttonTransfer = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_forward); |
| 67 | buttonHangUp = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_end_call); |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 68 | |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 69 | setDrawer(new ActionDrawer(0, 0, drawerPosition.UNDEFINED)); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 70 | |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public void expand(int width, int height) { |
| 75 | |
| 76 | expanded = true; |
| 77 | generateBitmap(); |
| 78 | if (pos.x < width / 3) { |
| 79 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 80 | // Left |
| 81 | act = new ActionDrawer(width * 2 / 3, (int) (getRadius() * 1.5f), drawerPosition.LEFT); |
| 82 | act.adjustBounds(pos.x, pos.y); |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 83 | act.generateBitmap(actions.NOTHING); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 84 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 85 | } else if (pos.x > 2 * width / 3) { |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 86 | // Right |
| 87 | act = new ActionDrawer(width * 2 / 3, (int) (getRadius() * 1.5f), drawerPosition.RIGHT); |
| 88 | act.adjustBounds(pos.x, pos.y); |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 89 | act.generateBitmap(actions.NOTHING); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 90 | |
| 91 | } else { |
| 92 | // Middle of the screen |
| 93 | if (pos.y < height / 3) { |
| 94 | // Middle Top |
| 95 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 96 | act = new ActionDrawer((int) (getRadius() * 1.5f), height / 2, drawerPosition.TOP); |
| 97 | act.adjustBounds(pos.x, pos.y); |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 98 | act.generateBitmap(actions.NOTHING); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 99 | |
| 100 | } else if (pos.y > 2 * height / 3) { |
| 101 | // Middle Bottom |
| 102 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 103 | act = new ActionDrawer((int) (getRadius() * 1.5f), height / 2, drawerPosition.BOTTOM); |
| 104 | act.adjustBounds(pos.x, pos.y); |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 105 | act.generateBitmap(actions.NOTHING); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 106 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | |
| 110 | } |
| 111 | |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame] | 112 | protected class ActionDrawer extends Bubble.ActionDrawer { |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 113 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 114 | int direction; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 115 | RectF boundsHoldButton, boundsMsgButton, boundsTransferButton, boundsHangUpButton; |
Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 116 | @SuppressWarnings("unused") |
Alexandre Lision | 5cd659e | 2013-10-29 13:18:23 -0400 | [diff] [blame] | 117 | private String TAG = ActionDrawer.class.getSimpleName(); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 118 | |
| 119 | int wHang, hHang; |
| 120 | int wHold, hHold; |
| 121 | int wMsg, hMsg; |
| 122 | int wTrans, hTrans; |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 123 | private RectF boundsTransferIcon,boundsMsgIcon, boundsHangIcon, boundsHoldIcon; |
| 124 | |
| 125 | private int LINE_PADDING = 25; |
| 126 | |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 127 | |
| 128 | Paint pButtons = new Paint(); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 129 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 130 | public ActionDrawer(int w, int h, int dir) { |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 131 | super(w, h); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 132 | direction = dir; |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 133 | |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 134 | wHang = buttonHangUp.getWidth(); |
| 135 | hHang = buttonHangUp.getHeight(); |
| 136 | |
| 137 | wMsg = buttonMsg.getWidth(); |
| 138 | hMsg = buttonMsg.getHeight(); |
| 139 | |
| 140 | wHold = buttonHold.getWidth(); |
| 141 | hHold = buttonHold.getHeight(); |
| 142 | |
| 143 | wTrans = buttonTransfer.getWidth(); |
| 144 | hTrans = buttonTransfer.getHeight(); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 145 | } |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame] | 146 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 147 | @Override |
| 148 | public int getAction(float x, float y) { |
| 149 | |
Alexandre Lision | 5cd659e | 2013-10-29 13:18:23 -0400 | [diff] [blame] | 150 | float relativeX = x - getDrawerBounds().left; |
| 151 | float relativeY = y - getDrawerBounds().top; |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 152 | |
Alexandre Lision | 5cd659e | 2013-10-29 13:18:23 -0400 | [diff] [blame] | 153 | int result = actions.NOTHING; |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 154 | |
| 155 | if (!getDrawerBounds().contains(x, y) && !getBounds().contains(x, y)) { |
Alexandre Lision | 5cd659e | 2013-10-29 13:18:23 -0400 | [diff] [blame] | 156 | return actions.OUT_OF_BOUNDS; |
| 157 | } |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 158 | |
| 159 | if (boundsHoldButton.contains(relativeX, relativeY)) { |
| 160 | Log.i("Bubble", "Holding"); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 161 | result = actions.HOLD; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | if (boundsMsgButton.contains(relativeX, relativeY)) { |
| 165 | Log.i("Bubble", "Msg"); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 166 | result = actions.MESSAGE; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | if (boundsHangUpButton.contains(relativeX, relativeY)) { |
| 170 | Log.i("Bubble", "hangUp"); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 171 | result = actions.HANGUP; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | if (boundsTransferButton.contains(relativeX, relativeY)) { |
| 175 | Log.i("Bubble", "Transfer"); |
Alexandre Lision | 5cd659e | 2013-10-29 13:18:23 -0400 | [diff] [blame] | 176 | result = actions.TRANSFER; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 177 | } |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 178 | |
Alexandre Lision | 5cd659e | 2013-10-29 13:18:23 -0400 | [diff] [blame] | 179 | return result; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 180 | |
| 181 | } |
| 182 | |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 183 | public void generateBitmap(int action) { |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 184 | |
| 185 | img = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 186 | Canvas c = new Canvas(img); |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 187 | c.drawRect(new RectF(0, 0, mWidth, mHeight), mBackgroundPaint); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 188 | float rHeight, rWidth; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 189 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 190 | switch (direction) { |
| 191 | case drawerPosition.TOP: |
| 192 | rHeight = bounds.height() - getRadius(); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 193 | boundsHoldButton = new RectF(0, getRadius(), mWidth, getRadius() + rHeight / 4); |
| 194 | boundsMsgButton = new RectF(0, getRadius() + rHeight / 4, mWidth, getRadius() + 2 * rHeight / 4); |
| 195 | boundsTransferButton = new RectF(0, getRadius() + 2 * rHeight / 4, mWidth, getRadius() + 3 * rHeight / 4); |
| 196 | boundsHangUpButton = new RectF(0, getRadius() + 3 * rHeight / 4, mWidth, getRadius() + rHeight); |
| 197 | |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 198 | calculateIconBounds(); |
| 199 | draw(c, action); |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 200 | |
| 201 | c.drawLine(LINE_PADDING, boundsHoldButton.bottom, mWidth - LINE_PADDING, boundsHoldButton.bottom, mLines); |
| 202 | c.drawLine(LINE_PADDING, boundsMsgButton.bottom, mWidth - LINE_PADDING, boundsMsgButton.bottom, mLines); |
| 203 | c.drawLine(LINE_PADDING, boundsTransferButton.bottom, mWidth - LINE_PADDING, boundsTransferButton.bottom, mLines); |
| 204 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 205 | break; |
| 206 | case drawerPosition.BOTTOM: |
| 207 | rHeight = bounds.height() - getRadius(); |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 208 | boundsHangUpButton = new RectF(0, 0, mWidth, rHeight / 4); |
| 209 | boundsTransferButton = new RectF(0, rHeight / 4, mWidth, 2 * rHeight / 4); |
| 210 | boundsMsgButton = new RectF(0, 2 * rHeight / 4, mWidth, 3 * rHeight / 4); |
| 211 | boundsHoldButton = new RectF(0, 3 * rHeight / 4, mWidth, rHeight); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 212 | |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 213 | calculateIconBounds(); |
| 214 | draw(c, action); |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 215 | |
| 216 | c.drawLine(LINE_PADDING, boundsHangUpButton.bottom, mWidth - LINE_PADDING, boundsHangUpButton.bottom, mLines); |
| 217 | c.drawLine(LINE_PADDING, boundsTransferButton.bottom, mWidth - LINE_PADDING, boundsTransferButton.bottom, mLines); |
| 218 | c.drawLine(LINE_PADDING, boundsMsgButton.bottom, mWidth - LINE_PADDING,boundsMsgButton.bottom, mLines); |
| 219 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 220 | break; |
| 221 | case drawerPosition.RIGHT: |
| 222 | rWidth = bounds.width() - getRadius(); |
| 223 | boundsHoldButton = new RectF(0, 0, rWidth / 4, mHeight); |
| 224 | boundsMsgButton = new RectF(rWidth / 4, 0, 2 * rWidth / 4, mHeight); |
| 225 | boundsTransferButton = new RectF(2 * rWidth / 4, 0, 3 * rWidth / 4, mHeight); |
| 226 | boundsHangUpButton = new RectF(3 * rWidth / 4, 0, rWidth, mHeight); |
| 227 | |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 228 | calculateIconBounds(); |
| 229 | draw(c, action); |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 230 | |
| 231 | c.drawLine(boundsHoldButton.right, LINE_PADDING, boundsHoldButton.right, mHeight - LINE_PADDING, mLines); |
| 232 | c.drawLine(boundsMsgButton.right, LINE_PADDING, boundsMsgButton.right, mHeight - LINE_PADDING, mLines); |
| 233 | c.drawLine(boundsTransferButton.right, LINE_PADDING, boundsTransferButton.right, mHeight - LINE_PADDING, mLines); |
| 234 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 235 | break; |
| 236 | case drawerPosition.LEFT: |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 237 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 238 | rWidth = bounds.width() - getRadius(); |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 239 | boundsHangUpButton = new RectF(getRadius(), 0, getRadius() + rWidth / 4, mHeight); |
| 240 | boundsTransferButton = new RectF(getRadius() + rWidth / 4, 0, getRadius() + 2 * rWidth / 4, mHeight); |
| 241 | boundsMsgButton = new RectF(getRadius() + 2 * rWidth / 4, 0, getRadius() + 3 * rWidth / 4, mHeight); |
| 242 | boundsHoldButton = new RectF(getRadius() + 3 * rWidth / 4, 0, getRadius() + rWidth, mHeight); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 243 | |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 244 | calculateIconBounds(); |
| 245 | draw(c, action); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 246 | break; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | } |
| 250 | |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 251 | |
| 252 | |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 253 | private void draw(Canvas c, int action) { |
| 254 | if (action == actions.HANGUP) { |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 255 | c.drawRect(boundsHangUpButton, mSelector); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 256 | } |
| 257 | c.drawBitmap(buttonHangUp, null, boundsHangIcon, pButtons); |
| 258 | |
| 259 | if (action == actions.HOLD) { |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 260 | c.drawRect(boundsHoldButton, mSelector); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 261 | } |
| 262 | if (associated_call.isOnHold()) { |
| 263 | c.drawBitmap(buttonUnhold, null, boundsHoldIcon, pButtons); |
| 264 | } else { |
| 265 | c.drawBitmap(buttonHold, null, boundsHoldIcon, pButtons); |
| 266 | } |
| 267 | if (action == actions.MESSAGE) { |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 268 | c.drawRect(boundsMsgButton, mSelector); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 269 | } |
| 270 | c.drawBitmap(buttonMsg, null, boundsMsgIcon, pButtons); |
| 271 | |
| 272 | if (action == actions.TRANSFER) { |
Alexandre Lision | d5ee396 | 2013-11-08 15:37:28 -0500 | [diff] [blame] | 273 | c.drawRect(boundsTransferButton, mSelector); |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 274 | } |
| 275 | c.drawBitmap(buttonTransfer, null, boundsTransferIcon, pButtons); |
| 276 | } |
| 277 | |
| 278 | private void calculateIconBounds() { |
| 279 | boundsHoldIcon = new RectF((int) boundsHoldButton.centerX() - wHold / 2, (int) boundsHoldButton.centerY() - hHold / 2, |
| 280 | (int) boundsHoldButton.centerX() + wHold / 2, (int) boundsHoldButton.centerY() + hHold / 2); |
| 281 | boundsHangIcon = new RectF((int) boundsHangUpButton.centerX() - wHang / 2, (int) boundsHangUpButton.centerY() - hHang / 2, |
| 282 | (int) boundsHangUpButton.centerX() + wHang / 2, (int) boundsHangUpButton.centerY() + hHang / 2); |
| 283 | boundsMsgIcon = new RectF((int) boundsMsgButton.centerX() - wMsg / 2, (int) boundsMsgButton.centerY() - hMsg / 2, |
| 284 | (int) boundsMsgButton.centerX() + wMsg / 2, (int) boundsMsgButton.centerY() + hMsg / 2); |
| 285 | boundsTransferIcon = new RectF((int) boundsTransferButton.centerX() - wTrans / 2, (int) boundsTransferButton.centerY() - hTrans / 2, |
| 286 | (int) boundsTransferButton.centerX() + wTrans / 2, (int) boundsTransferButton.centerY() + hTrans / 2); |
| 287 | } |
| 288 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 289 | public void adjustBounds(float x, float y) { |
| 290 | switch (direction) { |
| 291 | case drawerPosition.TOP: |
| 292 | setBounds(x - getRadius(), y, x + getRadius(), y + getHeight()); |
| 293 | break; |
| 294 | case drawerPosition.BOTTOM: |
| 295 | setBounds(x - getRadius(), y - getHeight(), x + getRadius(), y); |
| 296 | break; |
| 297 | case drawerPosition.RIGHT: |
| 298 | setBounds(x - getWidth(), y - getRadius(), x, y + +getRadius()); |
| 299 | break; |
| 300 | case drawerPosition.LEFT: |
| 301 | setBounds(x, y - getRadius(), x + getWidth(), y + getRadius()); |
| 302 | break; |
| 303 | } |
| 304 | |
| 305 | } |
| 306 | |
| 307 | @Override |
| 308 | public void setBounds(float left, float top, float right, float bottom) { |
| 309 | int margin = (int) (0.5f * getRadius()) / 2; |
| 310 | switch (direction) { |
| 311 | case drawerPosition.TOP: |
| 312 | case drawerPosition.BOTTOM: |
| 313 | super.setBounds(left + margin, top, right - margin, bottom); |
| 314 | break; |
| 315 | case drawerPosition.RIGHT: |
| 316 | case drawerPosition.LEFT: |
| 317 | super.setBounds(left, top + margin, right, bottom - margin); |
| 318 | break; |
| 319 | } |
| 320 | |
| 321 | } |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | public Bitmap getDrawerBitmap() { |
| 325 | return act.getBitmap(); |
| 326 | } |
| 327 | |
| 328 | public RectF getDrawerBounds() { |
Alexandre Lision | 5cd659e | 2013-10-29 13:18:23 -0400 | [diff] [blame] | 329 | return act.getDrawerBounds(); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | @Override |
| 333 | public void set(float x, float y, float s) { |
| 334 | scale = s; |
| 335 | pos.x = x; |
| 336 | pos.y = y; |
| 337 | if (!expanded) { |
| 338 | bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius()); |
| 339 | } else { |
| 340 | bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius()); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 341 | act.adjustBounds(pos.x, pos.y); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | |
| 345 | @Override |
| 346 | public int getRadius() { |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 347 | if (expanded) |
Alexandre Lision | a9485b8 | 2013-10-25 10:00:57 -0400 | [diff] [blame] | 348 | return (int) (radius * density); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 349 | return (int) (radius * scale * density); |
| 350 | } |
| 351 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 352 | @Override |
| 353 | public boolean getHoldStatus() { |
| 354 | if (associated_call.isOnHold()) |
| 355 | return true; |
| 356 | else |
| 357 | return false; |
| 358 | } |
| 359 | |
| 360 | @Override |
| 361 | public boolean getRecordStatus() { |
| 362 | if (associated_call.isRecording()) |
| 363 | return true; |
| 364 | else |
| 365 | return false; |
| 366 | } |
| 367 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 368 | public SipCall getCall() { |
| 369 | return associated_call; |
| 370 | } |
| 371 | |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame] | 372 | public void setCall(SipCall call) { |
| 373 | associated_call = call; |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 374 | if (expanded) { |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 375 | act.generateBitmap(actions.NOTHING); |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame] | 376 | } |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 377 | |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | @Override |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 381 | public String getName() { |
Alexandre Lision | a7ab2e3 | 2014-02-14 15:33:33 -0500 | [diff] [blame] | 382 | return associated_call.getmContact().getmDisplayName(); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | @Override |
| 386 | public boolean callIDEquals(String call) { |
| 387 | return associated_call.getCallId().contentEquals(call); |
| 388 | } |
| 389 | |
| 390 | @Override |
| 391 | public String getCallID() { |
| 392 | return associated_call.getCallId(); |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame] | 393 | } |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 394 | |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 395 | @Override |
| 396 | public boolean onDown(MotionEvent event) { |
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 397 | if (expanded) { |
| 398 | act.generateBitmap(act.getAction(event.getX(), event.getY())); |
| 399 | return false; |
| 400 | } |
| 401 | if (intersects(event.getX(), event.getY())) { |
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 402 | dragged = true; |
| 403 | last_drag = System.nanoTime(); |
| 404 | setPos(event.getX(), event.getY()); |
| 405 | target_scale = .8f; |
| 406 | return true; |
| 407 | } |
| 408 | return false; |
| 409 | } |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame] | 410 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 411 | } |