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; |
| 13 | |
| 14 | public class BubbleContact extends Bubble { |
| 15 | |
| 16 | public SipCall associated_call; |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame^] | 17 | Bitmap buttonMsg, buttonUnhold, buttonHold, buttonTransfer, buttonHangUp; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 18 | |
| 19 | public BubbleContact(Context context, SipCall call, float x, float y, float size) { |
| 20 | super(context, call.getContact(), x, y, size); |
| 21 | associated_call = call; |
| 22 | isUser = false; |
| 23 | setDrawer(new ActionDrawer(0, 0, false, false)); |
| 24 | buttonMsg = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_chat); |
| 25 | buttonHold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_pause_over_video); |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame^] | 26 | buttonUnhold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_play_over_video); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 27 | buttonTransfer = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_forward); |
| 28 | buttonHangUp = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_end_call); |
| 29 | |
| 30 | } |
| 31 | |
| 32 | @Override |
| 33 | public void expand(int width, int height) { |
| 34 | |
| 35 | expanded = true; |
| 36 | generateBitmap(); |
| 37 | if (pos.x < width / 3) { |
| 38 | |
| 39 | // Open on the right |
| 40 | act = new ActionDrawer(width * 2 / 3, getRadius() * 2, false, false); |
| 41 | act.setBounds(pos.x, pos.y - getRadius(), pos.x + act.getWidth(), pos.y + getRadius()); |
| 42 | act.generateBitmap(); |
| 43 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 44 | } else if (pos.x > 2 * width / 3) { |
| 45 | // Open on the left |
| 46 | act = new ActionDrawer(width * 2 / 3, getRadius() * 2, true, false); |
| 47 | act.setBounds(pos.x - act.getWidth(), pos.y - getRadius(), pos.x, pos.y + +getRadius()); |
| 48 | act.generateBitmap(); |
| 49 | |
| 50 | } else { |
| 51 | // Middle of the screen |
| 52 | if (pos.y < height / 3) { |
| 53 | // Middle Top |
| 54 | |
| 55 | act = new ActionDrawer((int) (getRadius() * 1.5f), height / 2, false, true); |
| 56 | int margin = (int) (0.5f * getRadius()) / 2; |
| 57 | act.setBounds(pos.x - getRadius() + margin, pos.y, pos.x + getRadius() - margin, pos.y + act.getHeight()); |
| 58 | act.generateBitmap(); |
| 59 | |
| 60 | } else if (pos.y > 2 * height / 3) { |
| 61 | // Middle Bottom |
| 62 | |
| 63 | act = new ActionDrawer(getRadius() * 2, height / 2, false, true); |
| 64 | act.setBounds(pos.x - getRadius(), pos.y - act.getHeight(), pos.x + getRadius(), pos.y); |
| 65 | act.generateBitmap(); |
| 66 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
| 70 | } |
| 71 | |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame^] | 72 | protected class ActionDrawer extends Bubble.ActionDrawer { |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 73 | |
| 74 | boolean isLeft, isTop; |
| 75 | RectF boundsHoldButton, boundsMsgButton, boundsTransferButton, boundsHangUpButton; |
| 76 | |
| 77 | public ActionDrawer(int w, int h, boolean left, boolean top) { |
| 78 | super(w, h); |
| 79 | isLeft = left; |
| 80 | isTop = top; |
| 81 | } |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame^] | 82 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 83 | @Override |
| 84 | public int getAction(float x, float y) { |
| 85 | |
| 86 | float relativeX = x - getBounds().left; |
| 87 | float relativeY = y - getBounds().top; |
| 88 | |
| 89 | if (boundsHoldButton.contains(relativeX, relativeY)) { |
| 90 | Log.i("Bubble", "Holding"); |
| 91 | return actions.HOLD; |
| 92 | } |
| 93 | |
| 94 | if (boundsMsgButton.contains(relativeX, relativeY)) { |
| 95 | Log.i("Bubble", "Msg"); |
| 96 | return actions.MESSAGE; |
| 97 | } |
| 98 | |
| 99 | if (boundsHangUpButton.contains(relativeX, relativeY)) { |
| 100 | Log.i("Bubble", "hangUp"); |
| 101 | return actions.HANGUP; |
| 102 | } |
| 103 | |
| 104 | if (boundsTransferButton.contains(relativeX, relativeY)) { |
| 105 | Log.i("Bubble", "Transfer"); |
| 106 | return actions.TRANSFER; |
| 107 | } |
| 108 | return 0; |
| 109 | |
| 110 | } |
| 111 | |
| 112 | public void generateBitmap() { |
| 113 | |
| 114 | img = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888); |
| 115 | Paint paint = new Paint(); |
| 116 | paint.setColor(mContext.getResources().getColor(R.color.sfl_action_blue)); |
| 117 | Canvas c = new Canvas(img); |
| 118 | c.drawRect(new RectF(0, 0, mWidth, mHeight), paint); |
| 119 | |
| 120 | Paint pButtons = new Paint(); |
| 121 | if (isTop) { |
| 122 | float rHeight = bounds.height() - getRadius(); |
| 123 | boundsHoldButton = new RectF(0, getRadius(), mWidth, getRadius() + rHeight / 4); |
| 124 | boundsMsgButton = new RectF(0, getRadius() + rHeight / 4, mWidth, getRadius() + 2 * rHeight / 4); |
| 125 | boundsTransferButton = new RectF(0, getRadius() + 2 * rHeight / 4, mWidth, getRadius() + 3 * rHeight / 4); |
| 126 | boundsHangUpButton = new RectF(0, getRadius() + 3 * rHeight / 4, mWidth, getRadius() + rHeight); |
| 127 | |
| 128 | int wHang = buttonHangUp.getWidth(); |
| 129 | int hHang = buttonHangUp.getHeight(); |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame^] | 130 | c.drawBitmap(buttonHangUp, null, new RectF((int) boundsHangUpButton.centerX() - wHang / 2, (int) boundsHangUpButton.centerY() - hHang |
| 131 | / 2, (int) boundsHangUpButton.centerX() + wHang / 2, (int) boundsHangUpButton.centerY() + hHang / 2), pButtons); |
| 132 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 133 | int wHold = buttonHold.getWidth(); |
| 134 | int hHold = buttonHold.getHeight(); |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame^] | 135 | if(associated_call.isOnHold()){ |
| 136 | c.drawBitmap(buttonUnhold, null, new RectF((int) boundsHoldButton.centerX() - wHold / 2, (int) boundsHoldButton.centerY() - hHold / 2, |
| 137 | (int) boundsHoldButton.centerX() + wHold / 2, (int) boundsHoldButton.centerY() + hHold / 2), pButtons); |
| 138 | } else { |
| 139 | c.drawBitmap(buttonHold, null, new RectF((int) boundsHoldButton.centerX() - wHold / 2, (int) boundsHoldButton.centerY() - hHold / 2, |
| 140 | (int) boundsHoldButton.centerX() + wHold / 2, (int) boundsHoldButton.centerY() + hHold / 2), pButtons); |
| 141 | } |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 142 | |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame^] | 143 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 144 | int wMsg = buttonMsg.getWidth(); |
| 145 | int hMsg = buttonMsg.getHeight(); |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame^] | 146 | |
| 147 | c.drawBitmap(buttonMsg, null, new RectF((int) boundsMsgButton.centerX() - wMsg / 2, (int) boundsMsgButton.centerY() - hMsg / 2, |
| 148 | (int) boundsMsgButton.centerX() + wMsg / 2, (int) boundsMsgButton.centerY() + hMsg / 2), pButtons); |
| 149 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 150 | int wTrans = buttonTransfer.getWidth(); |
| 151 | int hTrans = buttonTransfer.getHeight(); |
| 152 | |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame^] | 153 | c.drawBitmap(buttonTransfer, null, new RectF((int) boundsTransferButton.centerX() - wTrans / 2, (int) boundsTransferButton.centerY() |
| 154 | - hTrans / 2, (int) boundsTransferButton.centerX() + wTrans / 2, (int) boundsTransferButton.centerY() + hTrans / 2), pButtons); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | } |
| 158 | |
| 159 | } |
| 160 | |
| 161 | public Bitmap getDrawerBitmap() { |
| 162 | return act.getBitmap(); |
| 163 | } |
| 164 | |
| 165 | public RectF getDrawerBounds() { |
| 166 | return act.getBounds(); |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public void set(float x, float y, float s) { |
| 171 | scale = s; |
| 172 | pos.x = x; |
| 173 | pos.y = y; |
| 174 | if (!expanded) { |
| 175 | bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius()); |
| 176 | } else { |
| 177 | bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius()); |
| 178 | act.setBounds(pos.x - getRadius(), pos.y, pos.x + getRadius(), pos.y + act.getHeight()); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | @Override |
| 183 | public int getRadius() { |
| 184 | return (int) (radius * scale * density); |
| 185 | } |
| 186 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 187 | @Override |
| 188 | public boolean getHoldStatus() { |
| 189 | if (associated_call.isOnHold()) |
| 190 | return true; |
| 191 | else |
| 192 | return false; |
| 193 | } |
| 194 | |
| 195 | @Override |
| 196 | public boolean getRecordStatus() { |
| 197 | if (associated_call.isRecording()) |
| 198 | return true; |
| 199 | else |
| 200 | return false; |
| 201 | } |
| 202 | |
| 203 | @Override |
| 204 | public SipCall getCall() { |
| 205 | return associated_call; |
| 206 | } |
| 207 | |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame^] | 208 | @Override |
| 209 | public void setCall(SipCall call) { |
| 210 | associated_call = call; |
| 211 | if(expanded){ |
| 212 | act.generateBitmap(); |
| 213 | } |
| 214 | |
| 215 | } |
| 216 | |
| 217 | @Override |
| 218 | public void setConference(Conference c) { |
| 219 | } |
| 220 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 221 | } |