Skip to content
Snippets Groups Projects
Commit 0c9bd8fe authored by Adrien Béraud's avatar Adrien Béraud
Browse files

Bubbles: Honor screen density when drawing bubbles and attractors.

parent 85704183
Branches
Tags
No related merge requests found
No preview for this file type
...@@ -36,12 +36,12 @@ as that of the covered work. ...@@ -36,12 +36,12 @@ as that of the covered work.
android:layout_height="match_parent" > android:layout_height="match_parent" >
<FrameLayout <FrameLayout
android:id="@+id/ongoingcall_pane" android:id="@+id/calllist_pane"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />
<FrameLayout <FrameLayout
android:id="@+id/calllist_pane" android:id="@+id/ongoingcall_pane"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent" />
......
...@@ -11,26 +11,4 @@ ...@@ -11,26 +11,4 @@
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:focusable="true" /> android:focusable="true" />
<!-- <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:weightSum="2" >
<Button
android:id="@+id/add_bubble"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Add Bubble" />
<Button
android:id="@+id/remove_bubble"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Remove Bubble" />
</LinearLayout> -->
</RelativeLayout> </RelativeLayout>
\ No newline at end of file
...@@ -31,8 +31,6 @@ ...@@ -31,8 +31,6 @@
*/ */
package com.savoirfairelinux.sflphone.client; package com.savoirfairelinux.sflphone.client;
import java.util.Random;
import android.app.ActionBar; import android.app.ActionBar;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment; import android.app.Fragment;
...@@ -65,7 +63,6 @@ import com.savoirfairelinux.sflphone.fragments.HistoryFragment; ...@@ -65,7 +63,6 @@ import com.savoirfairelinux.sflphone.fragments.HistoryFragment;
import com.savoirfairelinux.sflphone.fragments.MenuFragment; import com.savoirfairelinux.sflphone.fragments.MenuFragment;
import com.savoirfairelinux.sflphone.interfaces.CallInterface; import com.savoirfairelinux.sflphone.interfaces.CallInterface;
import com.savoirfairelinux.sflphone.model.CallContact; import com.savoirfairelinux.sflphone.model.CallContact;
import com.savoirfairelinux.sflphone.model.CallContact.ContactBuilder;
import com.savoirfairelinux.sflphone.model.SipCall; import com.savoirfairelinux.sflphone.model.SipCall;
import com.savoirfairelinux.sflphone.service.CallManagerCallBack; import com.savoirfairelinux.sflphone.service.CallManagerCallBack;
import com.savoirfairelinux.sflphone.service.ISipService; import com.savoirfairelinux.sflphone.service.ISipService;
...@@ -214,11 +211,13 @@ public class SFLPhoneHomeActivity extends Activity implements ActionBar.TabListe ...@@ -214,11 +211,13 @@ public class SFLPhoneHomeActivity extends Activity implements ActionBar.TabListe
R.string.drawer_open, /* "open drawer" description for accessibility */ R.string.drawer_open, /* "open drawer" description for accessibility */
R.string.drawer_close /* "close drawer" description for accessibility */ R.string.drawer_close /* "close drawer" description for accessibility */
) { ) {
@Override
public void onDrawerClosed(View view) { public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle); getActionBar().setTitle(mTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
} }
@Override
public void onDrawerOpened(View drawerView) { public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle); getActionBar().setTitle(mDrawerTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
...@@ -425,7 +424,7 @@ public class SFLPhoneHomeActivity extends Activity implements ActionBar.TabListe ...@@ -425,7 +424,7 @@ public class SFLPhoneHomeActivity extends Activity implements ActionBar.TabListe
SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance(); SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance();
try { try {
callBuilder.startCallCreation().setAccountID(service.getAccountList().get(1).toString()).setCallType(SipCall.state.CALL_TYPE_OUTGOING); callBuilder.startCallCreation().setAccountID(service.getAccountList().get(0).toString()).setCallType(SipCall.state.CALL_TYPE_OUTGOING);
} catch (RemoteException e1) { } catch (RemoteException e1) {
Log.e(TAG,e1.toString()); Log.e(TAG,e1.toString());
} }
......
...@@ -36,6 +36,7 @@ import java.util.HashMap; ...@@ -36,6 +36,7 @@ import java.util.HashMap;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment; import android.app.Fragment;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PointF; import android.graphics.PointF;
import android.os.Bundle; import android.os.Bundle;
import android.os.RemoteException; import android.os.RemoteException;
...@@ -54,12 +55,14 @@ import com.savoirfairelinux.sflphone.model.BubbleModel; ...@@ -54,12 +55,14 @@ import com.savoirfairelinux.sflphone.model.BubbleModel;
import com.savoirfairelinux.sflphone.model.BubblesView; import com.savoirfairelinux.sflphone.model.BubblesView;
import com.savoirfairelinux.sflphone.model.CallContact; import com.savoirfairelinux.sflphone.model.CallContact;
import com.savoirfairelinux.sflphone.model.SipCall; import com.savoirfairelinux.sflphone.model.SipCall;
import com.savoirfairelinux.sflphone.service.CallManagerCallBack;
import com.savoirfairelinux.sflphone.service.ISipService; import com.savoirfairelinux.sflphone.service.ISipService;
public class CallFragment extends Fragment { public class CallFragment extends Fragment {
static final String TAG = "CallFragment"; static final String TAG = "CallFragment";
static final float BUBBLE_SIZE = 100;
private SipCall mCall; private SipCall mCall;
private BubblesView view; private BubblesView view;
...@@ -73,7 +76,10 @@ public class CallFragment extends Fragment { ...@@ -73,7 +76,10 @@ public class CallFragment extends Fragment {
private TextView contact_name_txt; private TextView contact_name_txt;
CallContact myself = CallContact.ContactBuilder.buildUserContact("Me"); private CallContact myself = CallContact.ContactBuilder.buildUserContact("Me");
private Bitmap hangup_icon;
private Bitmap call_icon;
@Override @Override
public void onCreate(Bundle savedBundle) { public void onCreate(Bundle savedBundle) {
...@@ -85,16 +91,15 @@ public class CallFragment extends Fragment { ...@@ -85,16 +91,15 @@ public class CallFragment extends Fragment {
Bundle b = getArguments(); Bundle b = getArguments();
mCall = b.getParcelable("CallInfo"); mCall = b.getParcelable("CallInfo");
//mCall.
} }
/** /**
* A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity. * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity.
*/ */
private static Callbacks sDummyCallbacks = new Callbacks() { private static Callbacks sDummyCallbacks = new Callbacks() {
@Override @Override
public void onSendMessage(SipCall call, String msg) { public void onSendMessage(SipCall call, String msg) {
} }
@Override @Override
...@@ -103,49 +108,34 @@ public class CallFragment extends Fragment { ...@@ -103,49 +108,34 @@ public class CallFragment extends Fragment {
@Override @Override
public void onCallAccepted(SipCall call) { public void onCallAccepted(SipCall call) {
// TODO Auto-generated method stub
} }
@Override @Override
public void onCallRejected(SipCall call) { public void onCallRejected(SipCall call) {
// TODO Auto-generated method stub
} }
@Override @Override
public void onCallEnded(SipCall call) { public void onCallEnded(SipCall call) {
// TODO Auto-generated method stub
} }
@Override @Override
public void onCallSuspended(SipCall call) { public void onCallSuspended(SipCall call) {
// TODO Auto-generated method stub
} }
@Override @Override
public void onCallResumed(SipCall call) { public void onCallResumed(SipCall call) {
// TODO Auto-generated method stub
} }
@Override @Override
public void onCalltransfered(SipCall call, String to) { public void onCalltransfered(SipCall call, String to) {
// TODO Auto-generated method stub
} }
@Override @Override
public void onRecordCall(SipCall call) { public void onRecordCall(SipCall call) {
// TODO Auto-generated method stub
} }
@Override @Override
public ISipService getService() { public ISipService getService() {
// TODO Auto-generated method stub
return null; return null;
} }
}; };
...@@ -201,14 +191,18 @@ public class CallFragment extends Fragment { ...@@ -201,14 +191,18 @@ public class CallFragment extends Fragment {
view = (BubblesView) rootView.findViewById(R.id.main_view); view = (BubblesView) rootView.findViewById(R.id.main_view);
view.setModel(model); view.setModel(model);
hangup_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_hangup);
call_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_call);
Log.i(TAG, "Starting fragment for call " + mCall.getCallId()); Log.i(TAG, "Starting fragment for call " + mCall.getCallId());
mCall.printCallInfo(); mCall.printCallInfo();
if (mCall.isRinging()) {
initOutGoingCallDisplay();
}
if (mCall.isIncoming() && mCall.isRinging()) { if (mCall.isIncoming() && mCall.isRinging()) {
initIncomingCallDisplay(); initIncomingCallDisplay();
} else {
if (mCall.isRinging()) {
initOutGoingCallDisplay();
} }
try { try {
if (mCall.isOutGoing() && mCallbacks.getService().getCall(mCall.getCallId()) == null) { if (mCall.isOutGoing() && mCallbacks.getService().getCall(mCall.getCallId()) == null) {
...@@ -220,6 +214,7 @@ public class CallFragment extends Fragment { ...@@ -220,6 +214,7 @@ public class CallFragment extends Fragment {
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, e.toString()); Log.e(TAG, e.toString());
} }
}
if(mCall.isOngoing()){ if(mCall.isOngoing()){
initNormalStateDisplay(); initNormalStateDisplay();
...@@ -231,81 +226,112 @@ public class CallFragment extends Fragment { ...@@ -231,81 +226,112 @@ public class CallFragment extends Fragment {
private void initNormalStateDisplay() { private void initNormalStateDisplay() {
Log.i(TAG, "Start normal display"); Log.i(TAG, "Start normal display");
// TODO off-thread image loading // TODO off-thread image loading
Bubble contact_bubble, me; Bubble contact_bubble = getBubbleFor(mCall.getContacts().get(0), screenCenter.x, screenCenter.y);
if (mCall.getContacts().get(0).getPhoto_id() > 0) { Bubble me = getBubbleFor(myself, screenCenter.x, screenCenter.y * 3 / 2);
/* contact_bubble.setPos(screenCenter.x, screenCenter.y);
me.setPos(screenCenter.x, screenCenter.y * 3 / 2);*/
/*if (mCall.getContacts().get(0).getPhoto_id() > 0) {
Bitmap photo = ContactPictureLoader.loadContactPhoto(getActivity().getContentResolver(), mCall.getContacts().get(0).getId()); Bitmap photo = ContactPictureLoader.loadContactPhoto(getActivity().getContentResolver(), mCall.getContacts().get(0).getId());
contact_bubble = new Bubble(getActivity(), screenCenter.x, screenCenter.y, 150, photo); contact_bubble = new Bubble(screenCenter.x, screenCenter.y, 150, photo);
} else { } else {
contact_bubble = new Bubble(getActivity(), screenCenter.x, screenCenter.y / 2 , 150, R.drawable.ic_contact_picture); contact_bubble = new Bubble(getActivity(), screenCenter.x, screenCenter.y / 2 , 150, R.drawable.ic_contact_picture);
} }
me = new Bubble(getActivity(), screenCenter.x, screenCenter.y * 3 / 2, 150, R.drawable.ic_contact_picture); me = new Bubble(getActivity(), screenCenter.x, screenCenter.y * 3 / 2, 150, R.drawable.ic_contact_picture);
*/
model.attractors.clear(); model.clearAttractors();
model.attractors.add(new Attractor(new PointF(metrics.widthPixels / 2, metrics.heightPixels * .8f), new Attractor.Callback() { model.addAttractor(new Attractor(new PointF(metrics.widthPixels / 2, metrics.heightPixels * .8f), 20, new Attractor.Callback() {
@Override @Override
public void onBubbleSucked(Bubble b) { public void onBubbleSucked(Bubble b) {
Log.w(TAG, "Bubble sucked ! "); Log.w(TAG, "Bubble sucked ! ");
mCallbacks.onCallEnded(mCall); mCallbacks.onCallEnded(mCall);
} }
})); }, hangup_icon));
contact_bubble.contact = mCall.getContacts().get(0); /* contact_bubble.contact = mCall.getContacts().get(0);
me.contact = myself; me.contact = myself;
model.listBubbles.add(contact_bubble); model.addBubble(contact_bubble);
model.listBubbles.add(me); model.addBubble(me);
contacts.put(mCall.getContacts().get(0), contact_bubble); contacts.put(mCall.getContacts().get(0), contact_bubble);
contacts.put(myself, me); contacts.put(myself, me);*/
} }
private void initIncomingCallDisplay() { private void initIncomingCallDisplay() {
Log.i(TAG, "Start incoming display"); Log.i(TAG, "Start incoming display");
model.attractors.clear();
model.attractors.add(new Attractor(new PointF(3 * metrics.widthPixels / 4, metrics.heightPixels / 4), new Attractor.Callback() { Bubble contact_bubble = getBubbleFor(mCall.getContacts().get(0), screenCenter.x, screenCenter.y);
contacts.put(mCall.getContacts().get(0), contact_bubble);
model.clearAttractors();
model.addAttractor(new Attractor(new PointF(3 * metrics.widthPixels / 4, metrics.heightPixels / 4), 20, new Attractor.Callback() {
@Override @Override
public void onBubbleSucked(Bubble b) { public void onBubbleSucked(Bubble b) {
mCallbacks.onCallAccepted(mCall); mCallbacks.onCallAccepted(mCall);
} }
})); }, call_icon));
model.attractors.add(new Attractor(new PointF(metrics.widthPixels / 4, metrics.heightPixels / 4), new Attractor.Callback() { model.addAttractor(new Attractor(new PointF(metrics.widthPixels / 4, metrics.heightPixels / 4), 20, new Attractor.Callback() {
@Override @Override
public void onBubbleSucked(Bubble b) { public void onBubbleSucked(Bubble b) {
mCallbacks.onCallRejected(mCall); mCallbacks.onCallRejected(mCall);
} }
})); }, hangup_icon));
} }
private void initOutGoingCallDisplay() { private void initOutGoingCallDisplay() {
Log.i(TAG, "Start outgoing display"); Log.i(TAG, "Start outgoing display");
// TODO off-thread image loading // TODO off-thread image loading
Bubble contact_bubble; Bubble contact_bubble = getBubbleFor(mCall.getContacts().get(0), screenCenter.x, screenCenter.y);
if (mCall.getContacts().get(0).getPhoto_id() > 0) {
Bitmap photo = ContactPictureLoader.loadContactPhoto(getActivity().getContentResolver(), mCall.getContacts().get(0).getId());
contact_bubble = new Bubble(getActivity(), screenCenter.x, screenCenter.y, 150, photo);
} else {
contact_bubble = new Bubble(getActivity(), screenCenter.x, screenCenter.y, 150, R.drawable.ic_contact_picture);
}
model.attractors.clear(); model.clearAttractors();
model.attractors.add(new Attractor(new PointF(metrics.widthPixels / 2, metrics.heightPixels * .8f), new Attractor.Callback() { model.addAttractor(new Attractor(new PointF(metrics.widthPixels / 2, metrics.heightPixels * .8f), 20, new Attractor.Callback() {
@Override @Override
public void onBubbleSucked(Bubble b) { public void onBubbleSucked(Bubble b) {
Log.w(TAG, "Bubble sucked ! "); Log.w(TAG, "Bubble sucked ! ");
mCallbacks.onCallEnded(mCall); mCallbacks.onCallEnded(mCall);
} }
})); }, hangup_icon));
contact_bubble.contact = mCall.getContacts().get(0); /*contact_bubble.contact = mCall.getContacts().get(0);
model.listBubbles.add(contact_bubble); model.addBubble(contact_bubble);
contacts.put(mCall.getContacts().get(0), contact_bubble); contacts.put(mCall.getContacts().get(0), contact_bubble);*/
}
/**
* Retrieves or create a bubble for a given contact.
* If the bubble exists, it is moved to the new location.
*
* @param contact The contact
* @param x Initial or new x position.
* @param y Initial or new y position.
* @return Bubble corresponding to the contact.
*/
private Bubble getBubbleFor(CallContact contact, float x, float y) {
Bubble contact_bubble = contacts.get(contact);
if(contact_bubble != null) {
contact_bubble.attractor.set(x, y);
return contact_bubble;
}
if (contact.getPhoto_id() > 0) {
Bitmap photo = ContactPictureLoader.loadContactPhoto(getActivity().getContentResolver(), mCall.getContacts().get(0).getId());
contact_bubble = new Bubble(x, y, BUBBLE_SIZE, photo);
} else {
contact_bubble = new Bubble(x, y, BUBBLE_SIZE, getActivity(), R.drawable.ic_contact_picture);
}
contact_bubble.contact = contact;
model.addBubble(contact_bubble);
contacts.put(contact, contact_bubble);
return contact_bubble;
} }
public void changeCallState(String callID, String newState) { public void changeCallState(String callID, String newState) {
Log.w(TAG, "Changing call state of "+callID); Log.w(TAG, "Changing call state of "+callID);
mCall.printCallInfo(); mCall.printCallInfo();
if(callID != mCall.getCallId()) if(!callID.equals(mCall.getCallId()))
return; return;
mCall.setCallState(newState); mCall.setCallState(newState);
......
package com.savoirfairelinux.sflphone.model; package com.savoirfairelinux.sflphone.model;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.RectF;
public class Attractor { public class Attractor {
...@@ -8,10 +12,36 @@ public class Attractor { ...@@ -8,10 +12,36 @@ public class Attractor {
public void onBubbleSucked(Bubble b); public void onBubbleSucked(Bubble b);
} }
PointF pos; final PointF pos;
Callback callback; final float radius;
public Attractor(PointF pos, Callback callback) {
final Callback callback;
private final Bitmap img;
private final RectF bounds = new RectF();
public Attractor(PointF pos, float radius, Callback callback, Bitmap img) {
this.pos = pos; this.pos = pos;
this.radius = radius;
this.callback = callback; this.callback = callback;
this.img = img;
}
public Attractor(PointF pos, float radius, Callback callback, Context c, int resId) {
this(pos, radius, callback, BitmapFactory.decodeResource(c.getResources(), resId));
}
public void setDensity(float density)
{
bounds.set(pos.x - radius*density, pos.y - radius*density, pos.x + radius*density, pos.y + radius*density);
}
public RectF getBounds() {
return bounds;
} }
public Bitmap getBitmap() {
return img;
}
} }
...@@ -24,6 +24,7 @@ public class Bubble ...@@ -24,6 +24,7 @@ public class Bubble
public float target_scale = 1.f; public float target_scale = 1.f;
private final float radius; private final float radius;
private float scale = 1.f; private float scale = 1.f;
private float density = 1.f;
public PointF speed = new PointF(0, 0); public PointF speed = new PointF(0, 0);
public PointF last_speed = new PointF(); public PointF last_speed = new PointF();
public PointF attractor = null; public PointF attractor = null;
...@@ -36,7 +37,7 @@ public class Bubble ...@@ -36,7 +37,7 @@ public class Bubble
this.attractor = attractor; this.attractor = attractor;
} }
public Bubble(Context c, float x, float y, float rad, Bitmap photo) { public Bubble(float x, float y, float rad, Bitmap photo) {
internalBMP = photo; internalBMP = photo;
pos.set(x, y); pos.set(x, y);
...@@ -68,18 +69,11 @@ public class Bubble ...@@ -68,18 +69,11 @@ public class Bubble
internalCanvas.drawBitmap(circle, 0, 0, mPaintPath); internalCanvas.drawBitmap(circle, 0, 0, mPaintPath);
} }
public Bubble(Context c, float x, float y, float rad, int resID) { public Bubble(float x, float y, float rad, Context c, int resID) {
// Initialize the bitmap object by loading an image from the resources folder // Initialize the bitmap object by loading an image from the resources folder
/*if (resID != -1) this(x, y, rad, BitmapFactory.decodeResource(c.getResources(), resID==-1 ? resID : R.drawable.ic_contact_picture));
internalBMP = BitmapFactory.decodeResource(c.getResources(), resID);
else
internalBMP = BitmapFactory.decodeResource(c.getResources(), R.drawable.ic_contact_picture);
*/
this(c, x, y, rad, BitmapFactory.decodeResource(c.getResources(), resID==-1 ? resID : R.drawable.ic_contact_picture));
} }
public Bitmap getBitmap() { public Bitmap getBitmap() {
return externalBMP; return externalBMP;
} }
...@@ -92,7 +86,7 @@ public class Bubble ...@@ -92,7 +86,7 @@ public class Bubble
scale = s; scale = s;
pos.x = x; pos.x = x;
pos.y = y; pos.y = y;
float rad = scale*radius; float rad = scale*radius*density;
bounds.left = pos.x - rad; bounds.left = pos.x - rad;
bounds.right = pos.x + rad; bounds.right = pos.x + rad;
bounds.top = pos.y - rad; bounds.top = pos.y - rad;
...@@ -144,4 +138,9 @@ public class Bubble ...@@ -144,4 +138,9 @@ public class Bubble
float tot_radius = this.radius + radius; float tot_radius = this.radius + radius;
return dx*dx + dy*dy < tot_radius*tot_radius; return dx*dx + dy*dy < tot_radius*tot_radius;
} }
public void setDensity(float density)
{
this.density = density;
}
} }
package com.savoirfairelinux.sflphone.model; package com.savoirfairelinux.sflphone.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import android.graphics.PointF; import android.graphics.PointF;
...@@ -8,10 +9,10 @@ public class BubbleModel ...@@ -8,10 +9,10 @@ public class BubbleModel
{ {
private static final String TAG = BubbleModel.class.getSimpleName(); private static final String TAG = BubbleModel.class.getSimpleName();
public long lastUpdate = 0; private long lastUpdate = 0;
public int width, height; public int width, height;
public ArrayList<Bubble> listBubbles = new ArrayList<Bubble>(); private ArrayList<Bubble> bubbles = new ArrayList<Bubble>();
public ArrayList<Attractor> attractors = new ArrayList<Attractor>(); private ArrayList<Attractor> attractors = new ArrayList<Attractor>();
private static final double BUBBLE_RETURN_TIME_HALF_LIFE = .3; private static final double BUBBLE_RETURN_TIME_HALF_LIFE = .3;
private static final double BUBBLE_RETURN_TIME_LAMBDA = Math.log(2)/BUBBLE_RETURN_TIME_HALF_LIFE; private static final double BUBBLE_RETURN_TIME_LAMBDA = Math.log(2)/BUBBLE_RETURN_TIME_HALF_LIFE;
...@@ -42,6 +43,35 @@ public class BubbleModel ...@@ -42,6 +43,35 @@ public class BubbleModel
border_repulsion = BORDER_REPULSION*density; border_repulsion = BORDER_REPULSION*density;
} }
public void addBubble(Bubble b) {
b.setDensity(density);
bubbles.add(b);
}
public List<Bubble> getBubbles()
{
return bubbles;
}
public void addAttractor(Attractor a) {
a.setDensity(density);
attractors.add(a);
}
public List<Attractor> getAttractors()
{
return attractors;
}
public void clearAttractors() {
attractors.clear();
}
public void clear() {
clearAttractors();
bubbles.clear();
}
public void update() public void update()
{ {
long now = System.nanoTime(); long now = System.nanoTime();
...@@ -60,8 +90,8 @@ public class BubbleModel ...@@ -60,8 +90,8 @@ public class BubbleModel
// Iterators should not be used in frequently called methods // Iterators should not be used in frequently called methods
// to avoid garbage collection glitches caused by iterator objects. // to avoid garbage collection glitches caused by iterator objects.
for(int i=0, n=listBubbles.size(); i<n; i++) { for(int i=0, n=bubbles.size(); i<n; i++) {
Bubble b = listBubbles.get(i); Bubble b = bubbles.get(i);
//Log.w(TAG, "update b"); //Log.w(TAG, "update b");
if(!b.dragged) { if(!b.dragged) {
...@@ -134,7 +164,7 @@ public class BubbleModel ...@@ -134,7 +164,7 @@ public class BubbleModel
if(attractor != null && attractor_dist < attractor_dist_suck*attractor_dist_suck) { if(attractor != null && attractor_dist < attractor_dist_suck*attractor_dist_suck) {
attractor.callback.onBubbleSucked(b); attractor.callback.onBubbleSucked(b);
listBubbles.remove(b); bubbles.remove(b);
n--; n--;
} }
} }
...@@ -143,4 +173,6 @@ public class BubbleModel ...@@ -143,4 +173,6 @@ public class BubbleModel
} }
} }
} }
package com.savoirfairelinux.sflphone.model; package com.savoirfairelinux.sflphone.model;
import java.util.List;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Paint.Align; import android.graphics.Paint.Align;
import android.graphics.RectF;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.util.AttributeSet; import android.util.AttributeSet;
...@@ -47,7 +48,7 @@ public class BubblesView extends SurfaceView implements SurfaceHolder.Callback, ...@@ -47,7 +48,7 @@ public class BubblesView extends SurfaceView implements SurfaceHolder.Callback,
attractor_paint.setColor(Color.RED); attractor_paint.setColor(Color.RED);
//attractor_paint.set //attractor_paint.set
name_paint.setTextSize(20*textDensity); name_paint.setTextSize(18*textDensity);
name_paint.setColor(0xFF303030); name_paint.setColor(0xFF303030);
name_paint.setTextAlign(Align.CENTER); name_paint.setTextAlign(Align.CENTER);
} }
...@@ -134,8 +135,13 @@ public class BubblesView extends SurfaceView implements SurfaceHolder.Callback, ...@@ -134,8 +135,13 @@ public class BubblesView extends SurfaceView implements SurfaceHolder.Callback,
int action = event.getActionMasked(); int action = event.getActionMasked();
synchronized (model) {
List<Bubble> bubbles = model.getBubbles();
final int n_bubbles = bubbles.size();
if (action == MotionEvent.ACTION_DOWN) { if (action == MotionEvent.ACTION_DOWN) {
for (Bubble b : model.listBubbles) { for(int i=0; i<n_bubbles; i++) {
Bubble b = bubbles.get(i);
if (b.intersects(event.getX(), event.getY())) { if (b.intersects(event.getX(), event.getY())) {
b.dragged = true; b.dragged = true;
b.last_drag = System.nanoTime(); b.last_drag = System.nanoTime();
...@@ -145,7 +151,8 @@ public class BubblesView extends SurfaceView implements SurfaceHolder.Callback, ...@@ -145,7 +151,8 @@ public class BubblesView extends SurfaceView implements SurfaceHolder.Callback,
} }
} else if (action == MotionEvent.ACTION_MOVE) { } else if (action == MotionEvent.ACTION_MOVE) {
long now = System.nanoTime(); long now = System.nanoTime();
for (Bubble b : model.listBubbles) { for(int i=0; i<n_bubbles; i++) {
Bubble b = bubbles.get(i);
if (b.dragged) { if (b.dragged) {
float x = event.getX(), y = event.getY(); float x = event.getX(), y = event.getY();
float dt = (float) ((now-b.last_drag)/1000000000.); float dt = (float) ((now-b.last_drag)/1000000000.);
...@@ -167,13 +174,16 @@ public class BubblesView extends SurfaceView implements SurfaceHolder.Callback, ...@@ -167,13 +174,16 @@ public class BubblesView extends SurfaceView implements SurfaceHolder.Callback,
} }
} }
} else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
for (Bubble b : model.listBubbles) { for(int i=0; i<n_bubbles; i++) {
Bubble b = bubbles.get(i);
if (b.dragged) { if (b.dragged) {
b.dragged = false; b.dragged = false;
b.target_scale = 1.f; b.target_scale = 1.f;
} }
} }
} }
}
return true; return true;
} }
...@@ -212,9 +222,6 @@ public class BubblesView extends SurfaceView implements SurfaceHolder.Callback, ...@@ -212,9 +222,6 @@ public class BubblesView extends SurfaceView implements SurfaceHolder.Callback,
doDraw(c); doDraw(c);
} }
} finally { } 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) if (c != null)
surfaceHolder.unlockCanvasAndPost(c); surfaceHolder.unlockCanvasAndPost(c);
} }
...@@ -233,9 +240,6 @@ public class BubblesView extends SurfaceView implements SurfaceHolder.Callback, ...@@ -233,9 +240,6 @@ public class BubblesView extends SurfaceView implements SurfaceHolder.Callback,
model.width = width; model.width = width;
model.height = height; model.height = height;
} }
// don't forget to resize the background image
// mBackgroundImage = Bitmap.createScaledBitmap(mBackgroundImage, width, height, true);
} }
} }
...@@ -244,23 +248,19 @@ public class BubblesView extends SurfaceView implements SurfaceHolder.Callback, ...@@ -244,23 +248,19 @@ public class BubblesView extends SurfaceView implements SurfaceHolder.Callback,
canvas.drawColor(Color.WHITE); canvas.drawColor(Color.WHITE);
synchronized (model) { synchronized (model) {
for (int i = 0; i < model.attractors.size(); i++) { List<Bubble> bubbles = model.getBubbles();
Attractor a = model.attractors.get(i); List<Attractor> attractors = model.getAttractors();
canvas.drawCircle(a.pos.x, a.pos.y, 10, attractor_paint);
} for (int i=0, n=attractors.size(); i < n; i++) {
Attractor a = attractors.get(i);
for (int i = 0; i < model.listBubbles.size(); i++) { //canvas.drawCircle(a.pos.x, a.pos.y, 10, attractor_paint);
Bubble b = model.listBubbles.get(i); canvas.drawBitmap(a.getBitmap(), null, a.getBounds(), null);
RectF bounds = new RectF(b.getBounds()); }
/*if(b.dragged) {
float width = bounds.left - bounds.right; for (int i=0, n=bubbles.size(); i<n; i++) {
float red = width/4; Bubble b = bubbles.get(i);
bounds.left += red; //RectF bounds = new RectF(b.getBounds());
bounds.right -= red; canvas.drawBitmap(b.getBitmap(), null, b.getBounds(), null);
bounds.top += red;
bounds.bottom -= red;
}*/
canvas.drawBitmap(b.getBitmap(), null, bounds, null);
canvas.drawText(b.contact.getmDisplayName(), b.getPosX(), b.getPosY()-50*density, name_paint); canvas.drawText(b.contact.getmDisplayName(), b.getPosX(), b.getPosY()-50*density, name_paint);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment