blob: 4c35710d4d9224fe541695507861e3cac210b2c0 [file] [log] [blame]
alisionfe9cf712013-05-03 17:26:08 -04001package com.savoirfairelinux.sflphone.model; // 41 Post - Created by DimasTheDriver on May/24/2012 . Part of the 'Android - rendering a Path with a Bitmap fill' post. http://www.41post.com/?p=4766
2
3import java.util.ArrayList;
4
5import com.savoirfairelinux.sflphone.R;
6
7import android.content.Context;
8import android.graphics.Canvas;
9import android.graphics.Color;
10import android.graphics.Paint;
11import android.util.AttributeSet;
12import android.util.Log;
13import android.view.MotionEvent;
14import android.view.View;
15
16public class BubblesView extends View {
17
18 private static final String TAG = BubblesView.class.getSimpleName();
19
20 ArrayList<Bubble> listBubbles;
21
22 Paint paint;
23
24 private int width;
25
26 private int height;
27
28 public BubblesView(Context context, AttributeSet attrs) {
29 super(context, attrs);
30
31 listBubbles = new ArrayList<Bubble>();
32 Bubble.Builder builder = new Bubble.Builder(getContext());
33 builder.setRadiusPixels(200).setX(200).setY(300).setResID(R.drawable.me);
34 listBubbles.add(builder.create());
35
36 builder.setRadiusPixels(200).setX(200).setY(700).setResID(R.drawable.callee);
37 listBubbles.add(builder.create());
38 // This View can receive focus, so it can react to touch events.
39 this.setFocusable(true);
40
41 paint = new Paint();
42
43 paint.setStyle(Paint.Style.FILL);
44 paint.setColor(Color.BLACK);
45 paint.setAntiAlias(true);
46 paint.setStrokeWidth(3);
47
48 }
49
50 @Override
51 public boolean onTouchEvent(MotionEvent event) {
52 // Store the position of the touch event at 'posX' and 'posY'
53 if (event.getAction() == MotionEvent.ACTION_MOVE) {
54
55 for (Bubble b : listBubbles) {
56 if (b.isPointWithin(event.getX(), event.getY())) {
57 b.setPosX(event.getX());
58 b.setPosY(event.getY());
59 invalidate();
60 return true;
61 }
62 }
63
64 }
65 return true;
66 }
67
68 @Override
69 public void onSizeChanged(int w, int h, int oldw, int oldh) {
70 super.onSizeChanged(w, h, oldw, oldh);
71 width = w;
72 height = h;
73 Log.i(TAG, "New Width " + w);
74 Log.i(TAG, "New Heigth " + h);
75 for (Bubble b : listBubbles) {
76 b.setRegion(w, h);
77 }
78 invalidate();
79 }
80
81 @Override
82 protected void onDraw(Canvas canvas) {
83
84 canvas.drawColor(Color.GRAY);
85 // canvas.drawLine(a.getPosX(), a.getPosY(), b.getPosX(), b.getPosY(), paint);
86
87 for (Bubble b : listBubbles) {
88 canvas.drawBitmap(b.getExternalBMP(), null, b.getBounds(), null);
89 }
90
91 }
92
93 public void addBubble() {
94 Bubble.Builder builder = new Bubble.Builder(getContext());
95 builder.setRadiusPixels(200).setX(200).setY(300);
96 listBubbles.add(builder.create());
97 listBubbles.get(listBubbles.size()-1).setRegion(width, height);
98 invalidate();
99 }
100}