Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 1 | package org.sflphone.model; |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 2 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 3 | import android.content.Context; |
| 4 | import android.graphics.Bitmap; |
| 5 | import android.graphics.BitmapFactory; |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 6 | import android.graphics.PointF; |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 7 | import android.graphics.RectF; |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 8 | |
| 9 | public class Attractor { |
| 10 | |
| 11 | public interface Callback { |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 12 | |
| 13 | /** |
| 14 | * Called when a bubble is on the "active" zone of the attractor. |
| 15 | * |
| 16 | * @param b The bubble that is on the attractor. |
| 17 | * @return true if the bubble should be removed from the model, false otherwise. |
| 18 | */ |
| 19 | public boolean onBubbleSucked(Bubble b); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 20 | } |
| 21 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 22 | final PointF pos; |
| 23 | final float radius; |
| 24 | |
| 25 | final Callback callback; |
| 26 | private final Bitmap img; |
| 27 | |
| 28 | private final RectF bounds = new RectF(); |
| 29 | |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 30 | public Attractor(PointF pos, float size, Callback callback, Bitmap img) { |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 31 | this.pos = pos; |
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 32 | this.radius = size/2; |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 33 | this.callback = callback; |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 34 | this.img = img; |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 35 | } |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 36 | |
| 37 | public Attractor(PointF pos, float radius, Callback callback, Context c, int resId) { |
| 38 | this(pos, radius, callback, BitmapFactory.decodeResource(c.getResources(), resId)); |
| 39 | } |
| 40 | |
| 41 | public void setDensity(float density) |
| 42 | { |
| 43 | bounds.set(pos.x - radius*density, pos.y - radius*density, pos.x + radius*density, pos.y + radius*density); |
| 44 | } |
| 45 | |
| 46 | public RectF getBounds() { |
| 47 | return bounds; |
| 48 | } |
| 49 | |
| 50 | public Bitmap getBitmap() { |
| 51 | return img; |
| 52 | } |
| 53 | |
| 54 | } |