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; |
| 11 | import android.graphics.RectF; |
| 12 | import android.util.Log; |
| 13 | |
| 14 | public class BubbleUser extends Bubble { |
| 15 | |
| 16 | public Conference associated_call; |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 17 | Bitmap buttonMic, buttonMicMuted, buttonHold, buttonUnhold, buttonRecord, buttonHangUp; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 18 | float expanded_radius; |
| 19 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 20 | public BubbleUser(Context context, CallContact m, Conference conf, float x, float y, float size) { |
| 21 | super(context, m, x, y, size); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 22 | isUser = true; |
| 23 | associated_call = conf; |
| 24 | setDrawer(new ActionDrawer(0, 0)); |
| 25 | expanded_radius = (float) (size * 1.5); |
| 26 | |
| 27 | buttonMic = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_mic); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 28 | buttonMicMuted = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_mic_muted); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 29 | buttonHold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_pause_over_video); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 30 | buttonUnhold = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_play_over_video); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 31 | // buttonRecord = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_); |
| 32 | buttonHangUp = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.ic_action_end_call); |
| 33 | } |
| 34 | |
| 35 | @Override |
| 36 | public void set(float x, float y, float s) { |
| 37 | scale = s; |
| 38 | pos.x = x; |
| 39 | pos.y = y; |
| 40 | bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius()); |
| 41 | if (!expanded) { |
| 42 | bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius()); |
| 43 | } else { |
| 44 | bounds.set(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius()); |
| 45 | act.setBounds(pos.x - getExpandedRadius(), pos.y - getExpandedRadius(), pos.x + getExpandedRadius(), pos.y + getExpandedRadius()); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public void expand(int width, int height) { |
| 51 | |
| 52 | expanded = true; |
| 53 | generateBitmap(); |
| 54 | setDrawer(new ActionDrawer((int) getExpandedRadius() * 2, (int) getExpandedRadius() * 2)); |
| 55 | |
| 56 | act.setBounds(pos.x - getExpandedRadius(), pos.y - getExpandedRadius(), pos.x + getExpandedRadius(), pos.y + getExpandedRadius()); |
| 57 | act.generateBitmap(); |
| 58 | |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public int getRadius() { |
| 63 | return (int) (radius * scale * density); |
| 64 | } |
| 65 | |
| 66 | public int getExpandedRadius() { |
| 67 | return (int) (expanded_radius * scale * density); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public boolean getHoldStatus() { |
| 72 | if (associated_call.isOnHold()) |
| 73 | return true; |
| 74 | else |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public boolean getRecordStatus() { |
| 80 | if (associated_call.isRecording()) |
| 81 | return true; |
| 82 | else |
| 83 | return false; |
| 84 | } |
| 85 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 86 | // @Override |
| 87 | public Conference getConference() { |
| 88 | return associated_call; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | protected class ActionDrawer extends Bubble.ActionDrawer { |
| 92 | |
| 93 | RectF boundsHoldButton, boundsMicButton, boundsRecordButton, boundsHangUpButton; |
| 94 | |
| 95 | public ActionDrawer(int w, int h) { |
| 96 | super(w, h); |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public void generateBitmap() { |
| 101 | img = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888); |
| 102 | Paint paint = new Paint(); |
| 103 | paint.setColor(mContext.getResources().getColor(R.color.sfl_action_blue)); |
| 104 | paint.setDither(true); |
| 105 | Canvas c = new Canvas(img); |
| 106 | c.drawOval(new RectF(0, 0, mWidth, mHeight), paint); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 107 | int wHang, hHang; |
| 108 | int wHold, hHold; |
| 109 | int wMic, hMic; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 110 | |
| 111 | Paint test4 = new Paint(); |
| 112 | boundsHangUpButton = new RectF(mWidth / 2 - getRadius(), 0, mWidth / 2 + getRadius(), mHeight / 2 - getRadius()); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 113 | wHang = buttonHangUp.getWidth(); |
| 114 | hHang = buttonHangUp.getHeight(); |
| 115 | c.drawBitmap(buttonHangUp, null, |
| 116 | new RectF((int) boundsHangUpButton.centerX() - wHang / 2, (int) boundsHangUpButton.centerY() - hHang / 2, |
| 117 | (int) boundsHangUpButton.centerX() + wHang / 2, (int) boundsHangUpButton.centerY() + hHang / 2), test4); |
| 118 | // c.drawBitmap(buttonHangUp, null, boundsHangUpButton, test4); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 119 | |
| 120 | boundsHoldButton = new RectF(0, mHeight / 2 - getRadius(), mWidth / 2 - getRadius(), mHeight / 2 + getRadius()); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 121 | // c.drawBitmap(buttonHold, null, boundsHoldButton, test4); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 122 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 123 | wHold = buttonHold.getWidth(); |
| 124 | hHold = buttonHold.getHeight(); |
| 125 | if (associated_call.isOnHold()) { |
| 126 | c.drawBitmap(buttonUnhold, null, new RectF((int) boundsHoldButton.centerX() - wHold / 2, |
| 127 | (int) boundsHoldButton.centerY() - hHold / 2, (int) boundsHoldButton.centerX() + wHold / 2, (int) boundsHoldButton.centerY() |
| 128 | + hHold / 2), test4); |
| 129 | } else { |
| 130 | c.drawBitmap(buttonHold, null, new RectF((int) boundsHoldButton.centerX() - wHold / 2, (int) boundsHoldButton.centerY() - hHold / 2, |
| 131 | (int) boundsHoldButton.centerX() + wHold / 2, (int) boundsHoldButton.centerY() + hHold / 2), test4); |
| 132 | } |
| 133 | |
| 134 | wMic = buttonMic.getWidth(); |
| 135 | hMic = buttonMic.getHeight(); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 136 | boundsMicButton = new RectF(mWidth / 2 + getRadius(), mHeight / 2 - getRadius(), mWidth, mHeight / 2 + getRadius()); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 137 | c.drawBitmap(buttonMic, null, new RectF((int) boundsMicButton.centerX() - wMic / 2, (int) boundsMicButton.centerY() - hMic / 2, |
| 138 | (int) boundsMicButton.centerX() + wMic / 2, (int) boundsMicButton.centerY() + hMic / 2), test4); |
| 139 | // c.drawBitmap(buttonMic, null, boundsMicButton, test4); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 140 | // // |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 141 | boundsRecordButton = new RectF(mWidth / 2 - getRadius(), mHeight / 2 + getRadius(), mWidth / 2 + getRadius(), mHeight); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 142 | // c.drawBitmap(buttonRecord, null, boundsRecordButton, test4); |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public int getAction(float x, float y) { |
| 147 | |
| 148 | float relativeX = x - getBounds().left; |
| 149 | float relativeY = y - getBounds().top; |
| 150 | |
| 151 | Log.i("Bubble", "relativeX:" + relativeX); |
| 152 | Log.i("Bubble", "relativeY:" + relativeY); |
| 153 | |
| 154 | Log.i("Bubble", "pos.x:" + pos.x); |
| 155 | Log.i("Bubble", "pos.y:" + pos.y); |
| 156 | // |
| 157 | // Log.i("Bubble", getBounds().toShortString()); |
| 158 | // |
| 159 | Log.i("boundsHoldButton", boundsHoldButton.toShortString()); |
| 160 | Log.i("boundsMicButton", boundsMicButton.toShortString()); |
| 161 | Log.i("boundsHangUpButton", boundsHangUpButton.toShortString()); |
| 162 | |
| 163 | if (boundsHoldButton.contains(relativeX, relativeY)) { |
| 164 | Log.i("Bubble", "Holding"); |
| 165 | return actions.HOLD; |
| 166 | } |
| 167 | |
| 168 | // if (boundsRecordButton.contains(x, y)) { |
| 169 | // Log.i("Bubble", "Record"); |
| 170 | // return actions.RECORD; |
| 171 | // } |
| 172 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 173 | if (boundsMicButton.contains(relativeX, relativeY)) { |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 174 | Log.i("Bubble", "Muting"); |
| 175 | return actions.MUTE; |
| 176 | } |
| 177 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 178 | if (boundsHangUpButton.contains(relativeX, relativeY)) { |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 179 | Log.i("Bubble", "hangup"); |
| 180 | return actions.HANGUP; |
| 181 | } |
| 182 | |
| 183 | return 0; |
| 184 | |
| 185 | } |
| 186 | |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public Bitmap getDrawerBitmap() { |
| 191 | return act.img; |
| 192 | } |
| 193 | |
| 194 | @Override |
| 195 | public RectF getDrawerBounds() { |
| 196 | return act.bounds; |
| 197 | } |
| 198 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 199 | public void setConference(Conference c) { |
| 200 | associated_call = c; |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | @Override |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 204 | public String getName() { |
| 205 | return mContext.getResources().getString(R.string.me); |
| 206 | } |
| 207 | |
| 208 | @Override |
| 209 | public boolean callIDEquals(String call) { |
| 210 | return associated_call.getId().contentEquals(call); |
| 211 | } |
| 212 | |
| 213 | @Override |
| 214 | public String getCallID() { |
| 215 | if (associated_call.hasMultipleParticipants()) |
| 216 | return associated_call.getId(); |
| 217 | else |
| 218 | return associated_call.getParticipants().get(0).getCallId(); |
| 219 | } |
| 220 | |
| 221 | @Override |
| 222 | public boolean isConference(){ |
| 223 | return associated_call.hasMultipleParticipants(); |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame] | 224 | } |
| 225 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 226 | } |