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