Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 1 | package org.sflphone.model; |
| 2 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 3 | import org.sflphone.R; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 4 | import org.sflphone.adapters.ContactPictureTask; |
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 5 | |
| 6 | import android.content.Context; |
| 7 | import android.graphics.Bitmap; |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 8 | import android.graphics.BitmapShader; |
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 9 | import android.graphics.Canvas; |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 10 | import android.graphics.Color; |
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 11 | import android.graphics.Paint; |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 12 | import android.graphics.Paint.Style; |
Adrien Béraud | 25fc409 | 2013-05-06 15:28:39 +1000 | [diff] [blame] | 13 | import android.graphics.PointF; |
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 14 | import android.graphics.RectF; |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 15 | import android.graphics.Shader; |
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 16 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 17 | public abstract class Bubble { |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 18 | |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 19 | // A Bitmap object that is going to be passed to the BitmapShader |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 20 | protected Bitmap externalBMP; |
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 21 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 22 | protected PointF pos = new PointF(); |
| 23 | protected RectF bounds; |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 24 | public float target_scale = 1.f; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 25 | protected float radius; |
| 26 | protected float scale = 1.f; |
| 27 | protected float density = 1.f; |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 28 | public PointF speed = new PointF(0, 0); |
| 29 | public PointF last_speed = new PointF(); |
| 30 | public PointF attractor = null; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 31 | ActionDrawer act; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 32 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 33 | public boolean isUser; |
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 34 | |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 35 | public boolean dragged = false; |
Alexandre Lision | 6deda41 | 2013-09-25 13:21:22 -0400 | [diff] [blame] | 36 | |
Alexandre Lision | 0edf18c | 2013-09-23 17:35:50 -0400 | [diff] [blame] | 37 | public boolean markedToDie = false; |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 38 | public long last_drag; |
| 39 | public boolean expanded; // determine if we draw the buttons around the bubble |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 40 | protected Bitmap saved_photo; |
alision | 4a0eb09 | 2013-05-07 13:52:03 -0400 | [diff] [blame] | 41 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 42 | public interface actions { |
| 43 | int NOTHING = 0; |
| 44 | int HOLD = 1; |
| 45 | int RECORD = 2; |
| 46 | int HANGUP = 3; |
| 47 | int MESSAGE = 4; |
| 48 | int TRANSFER = 5; |
| 49 | int MUTE = 6; |
| 50 | } |
| 51 | |
| 52 | protected Context mContext; |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 53 | |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 54 | public void setAttractor(PointF attractor) { |
| 55 | this.attractor = attractor; |
| 56 | } |
Adrien Béraud | e0ef0c2 | 2013-05-18 01:56:27 +1000 | [diff] [blame] | 57 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 58 | public Bubble(Context context, CallContact contact, float x, float y, float size) { |
| 59 | mContext = context; |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 60 | pos.set(x, y); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 61 | radius = size / 2; // 10 is the white stroke |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 62 | saved_photo = getContactPhoto(context, contact, (int) size); |
| 63 | generateBitmap(); |
| 64 | attractor = new PointF(x, y); |
Alexandre Lision | d568603 | 2013-10-29 11:09:21 -0400 | [diff] [blame] | 65 | isUser = false; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 66 | } |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 67 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 68 | protected void generateBitmap() { |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 69 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 70 | int w = saved_photo.getWidth(), h = saved_photo.getHeight(); |
| 71 | if (w > h) { |
| 72 | w = h; |
| 73 | } else if (h > w) { |
| 74 | h = w; |
| 75 | } |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 76 | externalBMP = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 77 | BitmapShader shader; |
| 78 | shader = new BitmapShader(saved_photo, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); |
| 79 | |
| 80 | Paint paint = new Paint(); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 81 | paint.setDither(true); |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 82 | paint.setAntiAlias(true); |
| 83 | paint.setShader(shader); |
| 84 | Canvas internalCanvas = new Canvas(externalBMP); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 85 | internalCanvas.drawCircle(w / 2, h / 2, w / 2, paint); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 86 | |
| 87 | Paint whiteStroke = new Paint(); |
| 88 | whiteStroke.setStyle(Style.STROKE); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 89 | whiteStroke.setStrokeWidth(8); |
| 90 | if (expanded) { |
| 91 | whiteStroke.setColor(mContext.getResources().getColor(R.color.sfl_action_blue)); |
| 92 | } else { |
| 93 | whiteStroke.setColor(Color.WHITE); |
| 94 | } |
| 95 | whiteStroke.setDither(true); |
| 96 | whiteStroke.setAntiAlias(true); |
| 97 | internalCanvas.drawCircle(w / 2, h / 2, w / 2 - 4, whiteStroke); |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 98 | |
| 99 | bounds = new RectF(pos.x - getRadius(), pos.y - getRadius(), pos.x + getRadius(), pos.y + getRadius()); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 100 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 101 | } |
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 102 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 103 | protected Bitmap getContactPhoto(Context context, CallContact contact, int size) { |
| 104 | if (contact.getPhoto_id() > 0) { |
| 105 | return ContactPictureTask.loadContactPhoto(context.getContentResolver(), contact.getId()); |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 106 | } else { |
| 107 | return ContactPictureTask.decodeSampledBitmapFromResource(context.getResources(), R.drawable.ic_contact_picture, (int) size, (int) size); |
| 108 | } |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 109 | } |
Adrien Béraud | 25fc409 | 2013-05-06 15:28:39 +1000 | [diff] [blame] | 110 | |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 111 | public Bitmap getBitmap() { |
| 112 | return externalBMP; |
| 113 | } |
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 114 | |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 115 | public RectF getBounds() { |
| 116 | return bounds; |
| 117 | } |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 118 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 119 | public abstract void set(float x, float y, float s); |
Adrien Béraud | 25fc409 | 2013-05-06 15:28:39 +1000 | [diff] [blame] | 120 | |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 121 | public float getPosX() { |
| 122 | return pos.x; |
| 123 | } |
Adrien Béraud | 25fc409 | 2013-05-06 15:28:39 +1000 | [diff] [blame] | 124 | |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 125 | public float getPosY() { |
| 126 | return pos.y; |
| 127 | } |
Adrien Béraud | 6bbce91 | 2013-05-24 00:48:13 +1000 | [diff] [blame] | 128 | |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 129 | public void setPos(float x, float y) { |
| 130 | set(x, y, scale); |
| 131 | } |
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 132 | |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 133 | public PointF getPos() { |
| 134 | return pos; |
| 135 | } |
Adrien Béraud | 25fc409 | 2013-05-06 15:28:39 +1000 | [diff] [blame] | 136 | |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 137 | public float getScale() { |
| 138 | return scale; |
| 139 | } |
Adrien Béraud | 25fc409 | 2013-05-06 15:28:39 +1000 | [diff] [blame] | 140 | |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 141 | public void setScale(float s) { |
| 142 | set(pos.x, pos.y, s); |
| 143 | } |
Adrien Béraud | 25fc409 | 2013-05-06 15:28:39 +1000 | [diff] [blame] | 144 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 145 | public abstract int getRadius(); |
Adrien Béraud | 6bbce91 | 2013-05-24 00:48:13 +1000 | [diff] [blame] | 146 | |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 147 | /** |
| 148 | * Point intersection test. |
| 149 | */ |
| 150 | boolean intersects(float x, float y) { |
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 151 | float dx = x - pos.x; |
| 152 | float dy = y - pos.y; |
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame] | 153 | |
Alexandre Lision | 5ed2c97 | 2013-10-11 15:36:33 -0400 | [diff] [blame] | 154 | return dx * dx + dy * dy < getRadius() * getRadius(); |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 155 | } |
Adrien Béraud | 6bbce91 | 2013-05-24 00:48:13 +1000 | [diff] [blame] | 156 | |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 157 | /** |
| 158 | * Other circle intersection test. |
| 159 | */ |
| 160 | boolean intersects(float x, float y, float radius) { |
| 161 | float dx = x - pos.x, dy = y - pos.y; |
| 162 | float tot_radius = getRadius() + radius; |
| 163 | return dx * dx + dy * dy < tot_radius * tot_radius; |
| 164 | } |
Adrien Béraud | 6bbce91 | 2013-05-24 00:48:13 +1000 | [diff] [blame] | 165 | |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 166 | public void setDensity(float density) { |
| 167 | this.density = density; |
| 168 | } |
Adrien Béraud | 25fc409 | 2013-05-06 15:28:39 +1000 | [diff] [blame] | 169 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 170 | public abstract void expand(int width, int height); |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 171 | |
| 172 | public void retract() { |
| 173 | expanded = false; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 174 | generateBitmap(); |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 175 | } |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 176 | |
Alexandre Lision | 0edf18c | 2013-09-23 17:35:50 -0400 | [diff] [blame] | 177 | public boolean isOnBorder(float w, float h) { |
| 178 | return (bounds.left < 0 || bounds.right > w || bounds.top < 0 || bounds.bottom > h); |
| 179 | } |
| 180 | |
alision | 729b0a2 | 2013-07-02 11:57:33 -0400 | [diff] [blame] | 181 | /** |
| 182 | * Always return the normal radius of the bubble |
alision | 91d2859 | 2013-07-02 14:33:53 -0400 | [diff] [blame] | 183 | * |
alision | 729b0a2 | 2013-07-02 11:57:33 -0400 | [diff] [blame] | 184 | * @return |
| 185 | */ |
| 186 | public float getRetractedRadius() { |
| 187 | return radius; |
| 188 | } |
| 189 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 190 | public abstract boolean getHoldStatus(); |
alision | 729b0a2 | 2013-07-02 11:57:33 -0400 | [diff] [blame] | 191 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 192 | public abstract boolean getRecordStatus(); |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 193 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 194 | public abstract Bitmap getDrawerBitmap(); |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 195 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 196 | public abstract RectF getDrawerBounds(); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 197 | |
| 198 | protected abstract class ActionDrawer { |
| 199 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 200 | int mWidth, mHeight; |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 201 | RectF bounds; |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 202 | Bitmap img; |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 203 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 204 | public ActionDrawer(int w, int h) { |
| 205 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 206 | mWidth = w; |
| 207 | mHeight = h; |
| 208 | bounds = new RectF(0, 0, 0, 0); |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 209 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 210 | } |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 211 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 212 | /** |
| 213 | * When the bubble is expanded we need to check on wich action button the user tap |
| 214 | * |
| 215 | * @param x |
| 216 | * @param y |
| 217 | * @return |
| 218 | */ |
| 219 | public abstract int getAction(float x, float y); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 220 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 221 | public void setBounds(float f, float y, float g, float h) { |
| 222 | bounds.set(f, y, g, h); |
| 223 | } |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 224 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 225 | public abstract void generateBitmap(); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 226 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 227 | public RectF getBounds() { |
| 228 | return bounds; |
| 229 | } |
| 230 | |
| 231 | public void setBounds(RectF bounds) { |
| 232 | this.bounds = bounds; |
| 233 | } |
| 234 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 235 | public Bitmap getBitmap() { |
| 236 | return img; |
| 237 | } |
| 238 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 239 | public int getWidth() { |
| 240 | return mWidth; |
| 241 | } |
| 242 | |
| 243 | public int getHeight() { |
| 244 | return mHeight; |
| 245 | } |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 246 | |
| 247 | public void adjustBounds(float x, float y) { |
| 248 | |
| 249 | } |
| 250 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 251 | } |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 252 | |
| 253 | public ActionDrawer getDrawer() { |
| 254 | return act; |
| 255 | } |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 256 | |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 257 | public void setDrawer(ActionDrawer a) { |
| 258 | act = a; |
| 259 | } |
| 260 | |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 261 | public abstract String getName(); |
| 262 | |
| 263 | public abstract boolean callIDEquals(String call); |
| 264 | |
| 265 | public abstract String getCallID(); |
| 266 | |
| 267 | public boolean isConference() { |
| 268 | return false; |
| 269 | } |
Alexandre Lision | ee2494d | 2013-10-09 17:14:00 -0400 | [diff] [blame] | 270 | |
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 271 | } |