blob: fed2690fed55baf5524d3c80fbf686001522c7ff [file] [log] [blame]
Adrien Béraud33268882013-05-18 03:41:15 +10001package com.savoirfairelinux.sflphone.model;
2
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +10003import android.content.Context;
4import android.graphics.Bitmap;
5import android.graphics.BitmapFactory;
Adrien Béraud33268882013-05-18 03:41:15 +10006import android.graphics.PointF;
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +10007import android.graphics.RectF;
Adrien Béraud33268882013-05-18 03:41:15 +10008
9public class Attractor {
10
11 public interface Callback {
Adrien Béraudc9c424d2013-05-30 17:47:35 +100012
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éraud33268882013-05-18 03:41:15 +100020 }
21
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +100022 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éraudc9c424d2013-05-30 17:47:35 +100030 public Attractor(PointF pos, float size, Callback callback, Bitmap img) {
Adrien Béraud33268882013-05-18 03:41:15 +100031 this.pos = pos;
Adrien Béraudc9c424d2013-05-30 17:47:35 +100032 this.radius = size/2;
Adrien Béraud33268882013-05-18 03:41:15 +100033 this.callback = callback;
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +100034 this.img = img;
Adrien Béraud33268882013-05-18 03:41:15 +100035 }
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +100036
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}