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