Bubbles: Honor screen density when drawing bubbles and attractors.
diff --git a/src/com/savoirfairelinux/sflphone/model/BubblesView.java b/src/com/savoirfairelinux/sflphone/model/BubblesView.java
index 1243275..8ca439a 100644
--- a/src/com/savoirfairelinux/sflphone/model/BubblesView.java
+++ b/src/com/savoirfairelinux/sflphone/model/BubblesView.java
@@ -1,11 +1,12 @@
package com.savoirfairelinux.sflphone.model;
+import java.util.List;
+
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
-import android.graphics.RectF;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
@@ -47,7 +48,7 @@
attractor_paint.setColor(Color.RED);
//attractor_paint.set
- name_paint.setTextSize(20*textDensity);
+ name_paint.setTextSize(18*textDensity);
name_paint.setColor(0xFF303030);
name_paint.setTextAlign(Align.CENTER);
}
@@ -134,46 +135,55 @@
int action = event.getActionMasked();
- if (action == MotionEvent.ACTION_DOWN) {
- for (Bubble b : model.listBubbles) {
- if (b.intersects(event.getX(), event.getY())) {
- b.dragged = true;
- b.last_drag = System.nanoTime();
- b.setPos(event.getX(), event.getY());
- b.target_scale = .8f;
- }
- }
- } else if (action == MotionEvent.ACTION_MOVE) {
- long now = System.nanoTime();
- for (Bubble b : model.listBubbles) {
- if (b.dragged) {
- float x = event.getX(), y = event.getY();
- float dt = (float) ((now-b.last_drag)/1000000000.);
- float dx = x - b.getPosX(), dy = y - b.getPosY();
- b.last_drag = now;
+ synchronized (model) {
+ List<Bubble> bubbles = model.getBubbles();
+ final int n_bubbles = bubbles.size();
- b.setPos(event.getX(), event.getY());
- /*int hn = event.getHistorySize() - 2;
+ if (action == MotionEvent.ACTION_DOWN) {
+ for(int i=0; i<n_bubbles; i++) {
+ Bubble b = bubbles.get(i);
+ if (b.intersects(event.getX(), event.getY())) {
+ b.dragged = true;
+ b.last_drag = System.nanoTime();
+ b.setPos(event.getX(), event.getY());
+ b.target_scale = .8f;
+ }
+ }
+ } else if (action == MotionEvent.ACTION_MOVE) {
+ long now = System.nanoTime();
+ for(int i=0; i<n_bubbles; i++) {
+ Bubble b = bubbles.get(i);
+ if (b.dragged) {
+ float x = event.getX(), y = event.getY();
+ float dt = (float) ((now-b.last_drag)/1000000000.);
+ float dx = x - b.getPosX(), dy = y - b.getPosY();
+ b.last_drag = now;
+
+ b.setPos(event.getX(), event.getY());
+ /*int hn = event.getHistorySize() - 2;
Log.w(TAG, "event.getHistorySize() : " + event.getHistorySize());
if(hn > 0) {
float dx = x-event.getHistoricalX(hn);
float dy = y-event.getHistoricalY(hn);
float dt = event.getHistoricalEventTime(hn)/1000.f;*/
- b.speed.x = dx/dt;
- b.speed.y = dy/dt;
- //Log.w(TAG, "onTouch dx:" + b.speed.x + " dy:" + b.speed.y);
- //}
- return true;
+ b.speed.x = dx/dt;
+ b.speed.y = dy/dt;
+ //Log.w(TAG, "onTouch dx:" + b.speed.x + " dy:" + b.speed.y);
+ //}
+ return true;
+ }
}
- }
- } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
- for (Bubble b : model.listBubbles) {
- if (b.dragged) {
- b.dragged = false;
- b.target_scale = 1.f;
+ } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
+ for(int i=0; i<n_bubbles; i++) {
+ Bubble b = bubbles.get(i);
+ if (b.dragged) {
+ b.dragged = false;
+ b.target_scale = 1.f;
+ }
}
}
}
+
return true;
}
@@ -212,9 +222,6 @@
doDraw(c);
}
} finally {
- // do this in a finally so that if an exception is thrown
- // during the above, we don't leave the Surface in an
- // inconsistent state
if (c != null)
surfaceHolder.unlockCanvasAndPost(c);
}
@@ -233,9 +240,6 @@
model.width = width;
model.height = height;
}
-
- // don't forget to resize the background image
- // mBackgroundImage = Bitmap.createScaledBitmap(mBackgroundImage, width, height, true);
}
}
@@ -244,23 +248,19 @@
canvas.drawColor(Color.WHITE);
synchronized (model) {
- for (int i = 0; i < model.attractors.size(); i++) {
- Attractor a = model.attractors.get(i);
- canvas.drawCircle(a.pos.x, a.pos.y, 10, attractor_paint);
+ List<Bubble> bubbles = model.getBubbles();
+ List<Attractor> attractors = model.getAttractors();
+
+ for (int i=0, n=attractors.size(); i < n; i++) {
+ Attractor a = attractors.get(i);
+ //canvas.drawCircle(a.pos.x, a.pos.y, 10, attractor_paint);
+ canvas.drawBitmap(a.getBitmap(), null, a.getBounds(), null);
}
- for (int i = 0; i < model.listBubbles.size(); i++) {
- Bubble b = model.listBubbles.get(i);
- RectF bounds = new RectF(b.getBounds());
- /*if(b.dragged) {
- float width = bounds.left - bounds.right;
- float red = width/4;
- bounds.left += red;
- bounds.right -= red;
- bounds.top += red;
- bounds.bottom -= red;
- }*/
- canvas.drawBitmap(b.getBitmap(), null, bounds, null);
+ for (int i=0, n=bubbles.size(); i<n; i++) {
+ Bubble b = bubbles.get(i);
+ //RectF bounds = new RectF(b.getBounds());
+ canvas.drawBitmap(b.getBitmap(), null, b.getBounds(), null);
canvas.drawText(b.contact.getmDisplayName(), b.getPosX(), b.getPosY()-50*density, name_paint);
}
}