blob: fb4a92df4e5808d2d66d58a19ed0487a4e6d7ce6 [file] [log] [blame]
alisioncc7bb422013-06-06 15:31:39 -04001/*
2 * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
3 *
4 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
5 * Adrien Béraud <adrien.beraud@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 * Additional permission under GNU GPL version 3 section 7:
22 *
23 * If you modify this program, or any covered work, by linking or
24 * combining it with the OpenSSL project's OpenSSL library (or a
25 * modified version of that library), containing parts covered by the
26 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
27 * grants you additional permission to convey the resulting work.
28 * Corresponding Source for a non-source form of such a combination
29 * shall include the source code for the parts of OpenSSL used as well
30 * as that of the covered work.
31 */
32
Alexandre Lision064e1e02013-10-01 16:18:42 -040033package org.sflphone.model;
alisionfe9cf712013-05-03 17:26:08 -040034
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +100035import java.util.List;
36
Alexandre Lision064e1e02013-10-01 16:18:42 -040037import org.sflphone.R;
38import org.sflphone.client.CallActivity;
39import org.sflphone.fragments.CallFragment;
40
alisionfe9cf712013-05-03 17:26:08 -040041import android.content.Context;
42import android.graphics.Canvas;
43import android.graphics.Color;
Adrien Béraud33268882013-05-18 03:41:15 +100044import android.graphics.Paint;
Adrien Béraud6bbce912013-05-24 00:48:13 +100045import android.graphics.Paint.Align;
Alexandre Lision23628c12013-09-24 11:17:05 -040046import android.graphics.Paint.Style;
Alexandre Lision0edf18c2013-09-23 17:35:50 -040047import android.graphics.RectF;
Adrien Béraud04463092013-05-06 14:17:22 +100048import android.os.Handler;
49import android.os.Message;
alisionfe9cf712013-05-03 17:26:08 -040050import android.util.AttributeSet;
51import android.util.Log;
alision58356b72013-06-03 17:13:36 -040052import android.view.GestureDetector;
53import android.view.GestureDetector.OnGestureListener;
alisionfe9cf712013-05-03 17:26:08 -040054import android.view.MotionEvent;
Adrien Béraud04463092013-05-06 14:17:22 +100055import android.view.SurfaceHolder;
56import android.view.SurfaceView;
alisionfe9cf712013-05-03 17:26:08 -040057import android.view.View;
Adrien Béraud04463092013-05-06 14:17:22 +100058import android.view.View.OnTouchListener;
alisionfe9cf712013-05-03 17:26:08 -040059
alision2cb99562013-05-30 17:02:20 -040060public class BubblesView extends SurfaceView implements SurfaceHolder.Callback, OnTouchListener {
61 private static final String TAG = BubblesView.class.getSimpleName();
alisionfe9cf712013-05-03 17:26:08 -040062
alision2cb99562013-05-30 17:02:20 -040063 private BubblesThread thread = null;
64 private BubbleModel model;
alisionfe9cf712013-05-03 17:26:08 -040065
alision2cb99562013-05-30 17:02:20 -040066 private Paint attractor_paint = new Paint();
alision34673e62013-06-25 14:40:07 -040067 private Paint black_name_paint = new Paint(Paint.ANTI_ALIAS_FLAG);
68 private Paint white_name_paint = new Paint(Paint.ANTI_ALIAS_FLAG);
Adrien Béraud6bbce912013-05-24 00:48:13 +100069
alisione38001f2013-06-04 14:14:39 -040070 private GestureDetector gDetector;
71
alision2cb99562013-05-30 17:02:20 -040072 private float density;
73 private float textDensity;
Adrien Béraud33268882013-05-18 03:41:15 +100074
alision2cb99562013-05-30 17:02:20 -040075 private boolean dragging_bubble = false;
Adrien Béraudc9c424d2013-05-30 17:47:35 +100076
alision34673e62013-06-25 14:40:07 -040077 private CallFragment callback;
78
alision2cb99562013-05-30 17:02:20 -040079 public BubblesView(Context context, AttributeSet attrs) {
80 super(context, attrs);
alisionfe9cf712013-05-03 17:26:08 -040081
alision2cb99562013-05-30 17:02:20 -040082 density = getResources().getDisplayMetrics().density;
83 textDensity = getResources().getDisplayMetrics().scaledDensity;
Adrien Béraud6bbce912013-05-24 00:48:13 +100084
alision2cb99562013-05-30 17:02:20 -040085 SurfaceHolder holder = getHolder();
86 holder.addCallback(this);
alisionfe9cf712013-05-03 17:26:08 -040087
alision2cb99562013-05-30 17:02:20 -040088 // create thread only; it's started in surfaceCreated()
89 createThread();
alisionfe9cf712013-05-03 17:26:08 -040090
alision2cb99562013-05-30 17:02:20 -040091 setOnTouchListener(this);
92 setFocusable(true);
Adrien Béraud33268882013-05-18 03:41:15 +100093
alision2cb99562013-05-30 17:02:20 -040094 attractor_paint.setColor(Color.RED);
95 // attractor_paint.set
alision34673e62013-06-25 14:40:07 -040096 black_name_paint.setTextSize(18 * textDensity);
97 black_name_paint.setColor(0xFF303030);
98 black_name_paint.setTextAlign(Align.CENTER);
99
100 white_name_paint.setTextSize(18 * textDensity);
101 white_name_paint.setColor(0xFFEEEEEE);
102 white_name_paint.setTextAlign(Align.CENTER);
alision58356b72013-06-03 17:13:36 -0400103
104 gDetector = new GestureDetector(getContext(), new MyOnGestureListener());
alision2cb99562013-05-30 17:02:20 -0400105 }
alisionfe9cf712013-05-03 17:26:08 -0400106
alision2cb99562013-05-30 17:02:20 -0400107 private void createThread() {
108 if (thread != null)
109 return;
110 thread = new BubblesThread(getHolder(), getContext(), new Handler() {
111 @Override
112 public void handleMessage(Message m) {
113 /*
114 * mStatusText.setVisibility(m.getData().getInt("viz")); mStatusText.setText(m.getData().getString("text"));
115 */
116 }
117 });
118 if (model != null)
119 thread.setModel(model);
120 }
alisionfe9cf712013-05-03 17:26:08 -0400121
alision2cb99562013-05-30 17:02:20 -0400122 public void setModel(BubbleModel model) {
123 this.model = model;
124 thread.setModel(model);
125 }
alisionfe9cf712013-05-03 17:26:08 -0400126
alision2cb99562013-05-30 17:02:20 -0400127 /*
128 * @Override public void onWindowFocusChanged(boolean hasWindowFocus) { if (!hasWindowFocus) { thread.pause(); } }
129 */
alisionfe9cf712013-05-03 17:26:08 -0400130
alision2cb99562013-05-30 17:02:20 -0400131 @Override
132 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
133 Log.w(TAG, "surfaceChanged " + width + "-" + height);
Alexandre Lision84208a32013-09-25 13:18:37 -0400134 if(height < model.height) // probably showing the keyboard, don't move!
135 return;
136
137
alision2cb99562013-05-30 17:02:20 -0400138 thread.setSurfaceSize(width, height);
139 }
alisionfe9cf712013-05-03 17:26:08 -0400140
alision2cb99562013-05-30 17:02:20 -0400141 /*
142 * Callback invoked when the Surface has been created and is ready to be used.
143 */
144 @Override
145 public void surfaceCreated(SurfaceHolder holder) {
146 // start the thread here so that we don't busy-wait in run()
147 // waiting for the surface to be created
148 createThread();
alisionfe9cf712013-05-03 17:26:08 -0400149
alision2cb99562013-05-30 17:02:20 -0400150 Log.w(TAG, "surfaceCreated");
151 thread.setRunning(true);
152 thread.start();
153 }
alisionfe9cf712013-05-03 17:26:08 -0400154
alision2cb99562013-05-30 17:02:20 -0400155 /*
156 * Callback invoked when the Surface has been destroyed and must no longer be touched. WARNING: after this method returns, the Surface/Canvas must
157 * never be touched again!
158 */
159 @Override
160 public void surfaceDestroyed(SurfaceHolder holder) {
161 // we have to tell thread to shut down & wait for it to finish, or else
162 // it might touch the Surface after we return and explode
163 Log.w(TAG, "surfaceDestroyed");
164 boolean retry = true;
165 thread.setRunning(false);
alision1005ba12013-06-19 13:52:44 -0400166 thread.setPaused(false);
alision2cb99562013-05-30 17:02:20 -0400167 while (retry) {
168 try {
alision1005ba12013-06-19 13:52:44 -0400169 Log.w(TAG, "joining...");
alision2cb99562013-05-30 17:02:20 -0400170 thread.join();
171 retry = false;
172 } catch (InterruptedException e) {
173 }
174 }
alision1005ba12013-06-19 13:52:44 -0400175 Log.w(TAG, "done");
alision2cb99562013-05-30 17:02:20 -0400176 thread = null;
177 }
alisionfe9cf712013-05-03 17:26:08 -0400178
alision2cb99562013-05-30 17:02:20 -0400179 public boolean isDraggingBubble() {
180 return dragging_bubble;
181 }
Adrien Béraudc9c424d2013-05-30 17:47:35 +1000182
alision2cb99562013-05-30 17:02:20 -0400183 class BubblesThread extends Thread {
184 private boolean running = false;
185 private SurfaceHolder surfaceHolder;
alisione38001f2013-06-04 14:14:39 -0400186 public Boolean suspendFlag = false;
alisionfe9cf712013-05-03 17:26:08 -0400187
alision2cb99562013-05-30 17:02:20 -0400188 BubbleModel model = null;
alisionfe9cf712013-05-03 17:26:08 -0400189
alision2cb99562013-05-30 17:02:20 -0400190 public BubblesThread(SurfaceHolder holder, Context context, Handler handler) {
191 surfaceHolder = holder;
192 }
alisionfe9cf712013-05-03 17:26:08 -0400193
alision2cb99562013-05-30 17:02:20 -0400194 public void setModel(BubbleModel model) {
195 this.model = model;
196 }
alisionfe9cf712013-05-03 17:26:08 -0400197
alision2cb99562013-05-30 17:02:20 -0400198 @Override
199 public void run() {
200 while (running) {
201 Canvas c = null;
202 try {
Adrien Béraud7ed23dc2013-05-06 16:27:24 +1000203
alisione38001f2013-06-04 14:14:39 -0400204 if (suspendFlag) {
205 synchronized (this) {
206 while (suspendFlag) {
207 try {
208 wait();
209 } catch (InterruptedException e) {
210 // TODO Auto-generated catch block
211 e.printStackTrace();
212 }
213 }
214 }
215 } else {
alisione38001f2013-06-04 14:14:39 -0400216 c = surfaceHolder.lockCanvas(null);
Adrien Béraud7ed23dc2013-05-06 16:27:24 +1000217
alisione38001f2013-06-04 14:14:39 -0400218 // for the case the surface is destroyed while already in the loop
219 if (c == null || model == null)
220 continue;
221
222 synchronized (surfaceHolder) {
223 // Log.w(TAG, "Thread doDraw");
224 model.update();
225 doDraw(c);
226 }
alision2cb99562013-05-30 17:02:20 -0400227 }
alisione38001f2013-06-04 14:14:39 -0400228
alision2cb99562013-05-30 17:02:20 -0400229 } finally {
230 if (c != null)
231 surfaceHolder.unlockCanvasAndPost(c);
232 }
233 }
234 }
Adrien Béraud04463092013-05-06 14:17:22 +1000235
alisione38001f2013-06-04 14:14:39 -0400236 public void setPaused(boolean wantToPause) {
237 synchronized (this) {
238 suspendFlag = wantToPause;
239 notify();
240 }
241 }
242
alision2cb99562013-05-30 17:02:20 -0400243 public void setRunning(boolean b) {
244 running = b;
245 }
Adrien Béraud04463092013-05-06 14:17:22 +1000246
alision2cb99562013-05-30 17:02:20 -0400247 public void setSurfaceSize(int width, int height) {
248 synchronized (surfaceHolder) {
249 if (model != null) {
250 model.width = width;
251 model.height = height;
252 }
253 }
254 }
Adrien Béraud04463092013-05-06 14:17:22 +1000255
alision2cb99562013-05-30 17:02:20 -0400256 /**
257 * I got multiple IndexOutOfBoundsException, when switching calls. //FIXME
258 *
259 * @param canvas
260 */
261 private void doDraw(Canvas canvas) {
Adrien Béraud04463092013-05-06 14:17:22 +1000262
alision2cb99562013-05-30 17:02:20 -0400263 synchronized (model) {
264 List<Bubble> bubbles = model.getBubbles();
265 List<Attractor> attractors = model.getAttractors();
Alexandre Lision0edf18c2013-09-23 17:35:50 -0400266
267 Paint tryMe = new Paint();
268
269 canvas.drawColor(Color.WHITE);
270
271 if (dragging_bubble) {
272 // Draw red gradient around to hang up call
273 // canvas.drawColor(Color.RED);
274
Alexandre Lision23628c12013-09-24 11:17:05 -0400275 // LinearGradient grTop = new LinearGradient(0, 0, 0, 40, Color.RED, Color.WHITE, TileMode.CLAMP);
276 // RadialGradient gr = new RadialGradient(model.width/2, model.height/2, model.width/2, Color.WHITE, Color.RED, TileMode.CLAMP);
Alexandre Lision0edf18c2013-09-23 17:35:50 -0400277 Paint p = new Paint();
278 p.setDither(true);
Alexandre Lision23628c12013-09-24 11:17:05 -0400279 // p.setShader(gr);
280 p.setColor(getResources().getColor(R.color.holo_red_light));
281 // p.setXfermode(new PorterDuffXfermode(Mode.))
282 p.setStyle(Style.STROKE);
283 // canvas.drawRect(new RectF(0, 0, model.width, 40), p);
284 p.setStrokeWidth(20);
Alexandre Lision0edf18c2013-09-23 17:35:50 -0400285
Alexandre Lision23628c12013-09-24 11:17:05 -0400286 canvas.drawRect(new RectF(10, 10, model.width - 10, model.height - 10), p);
Alexandre Lision0edf18c2013-09-23 17:35:50 -0400287
Alexandre Lision23628c12013-09-24 11:17:05 -0400288 // canvas.drawRoundRect(new RectF(0,0,model.width, model.height), 200, 200, p);
Alexandre Lision0edf18c2013-09-23 17:35:50 -0400289
Alexandre Lision23628c12013-09-24 11:17:05 -0400290 // LinearGradient grBottom = new LinearGradient(0, model.height, 0, model.height - 40, Color.RED, Color.WHITE, TileMode.CLAMP);
291 // p.setDither(true);
292 // p.setShader(grBottom);
293 // canvas.drawRect(new RectF(0, model.height - 40, model.width, model.height), p);
294 //
295 // LinearGradient grLeft = new LinearGradient(0, 0, 40, 0, Color.RED, Color.WHITE, TileMode.CLAMP);
296 // p.setDither(true);
297 // p.setShader(grLeft);
298 // canvas.drawRect(new RectF(0, 0, 40, model.height), p);
299 //
300 // LinearGradient grRight = new LinearGradient(model.width, 0, model.width - 40, 0, Color.RED, Color.WHITE, TileMode.CLAMP);
301 // p.setDither(true);
302 // p.setShader(grRight);
303 // canvas.drawRect(new RectF(model.width - 40, 0, model.width, model.height), p);
Alexandre Lision0edf18c2013-09-23 17:35:50 -0400304
305 // tryMe.setColor(getResources().getColor(R.color.lighter_gray));
306 // tryMe.setStyle(Paint.Style.FILL);
307 // tryMe.setXfermode(new PorterDuffXfermode(Mode.SRC_OUT));
308 // canvas.drawArc(new RectF(15, 30, model.width - 15, model.height - 30), 0, 360, false, tryMe);
309 }
310
311 tryMe.setStyle(Paint.Style.STROKE);
312 tryMe.setColor(getResources().getColor(R.color.darker_gray));
313 tryMe.setXfermode(null);
314 canvas.drawCircle(model.width / 2, model.height / 2, model.width / 2 - getResources().getDimension(R.dimen.bubble_size), tryMe);
315
alision2cb99562013-05-30 17:02:20 -0400316 try {
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000317
alision2cb99562013-05-30 17:02:20 -0400318 for (int i = 0, n = attractors.size(); i < n; i++) {
319 Attractor a = attractors.get(i);
320 canvas.drawBitmap(a.getBitmap(), null, a.getBounds(), null);
321 }
Adrien Béraud33268882013-05-18 03:41:15 +1000322
alision2cb99562013-05-30 17:02:20 -0400323 for (int i = 0, n = bubbles.size(); i < n; i++) {
324 Bubble b = bubbles.get(i);
Alexandre Lision0edf18c2013-09-23 17:35:50 -0400325 if (b.expanded) {
alision465ceba2013-07-04 09:24:30 -0400326 continue;
327 }
alision2cb99562013-05-30 17:02:20 -0400328 canvas.drawBitmap(b.getBitmap(), null, b.getBounds(), null);
Alexandre Lision0edf18c2013-09-23 17:35:50 -0400329 canvas.drawText(b.associated_call.getContact().getmDisplayName(), b.getPosX(), (float) (b.getPosY() - b.getRetractedRadius()
330 * 1.2 * density), getNamePaint(b));
alision34673e62013-06-25 14:40:07 -0400331 }
Alexandre Lision0edf18c2013-09-23 17:35:50 -0400332
alision34673e62013-06-25 14:40:07 -0400333 Bubble first_plan = getExpandedBubble();
334 if (first_plan != null) {
335 canvas.drawBitmap(first_plan.getBitmap(), null, first_plan.getBounds(), null);
Alexandre Lision0edf18c2013-09-23 17:35:50 -0400336
alision729b0a22013-07-02 11:57:33 -0400337 canvas.drawText(first_plan.associated_call.getContact().getmDisplayName(), first_plan.getPosX(),
alision465ceba2013-07-04 09:24:30 -0400338 (float) (first_plan.getPosY() - first_plan.getRetractedRadius() * 1.2 * density), getNamePaint(first_plan));
Alexandre Lision0edf18c2013-09-23 17:35:50 -0400339
Alexandre Lision42ea3c62013-09-25 13:20:31 -0400340 canvas.drawText(getResources().getString(R.string.action_call_general_transfer), first_plan.getPosX(),
341 (float) (first_plan.getPosY() + first_plan.getRetractedRadius() * 1.5 * density), getNamePaint(first_plan));
alisiondf1dac92013-06-27 17:35:53 -0400342
alision729b0a22013-07-02 11:57:33 -0400343 canvas.drawText(getResources().getString(first_plan.getHoldStatus()),
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400344 (float) (first_plan.getPosX() - first_plan.getRetractedRadius() * 1.5 * density - 15), first_plan.getPosY(),
alision729b0a22013-07-02 11:57:33 -0400345 getNamePaint(first_plan));
346
347 canvas.drawText(getResources().getString(first_plan.getRecordStatus()),
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400348 (float) (first_plan.getPosX() + first_plan.getRetractedRadius() * 1.5 * density + 15), first_plan.getPosY(),
alision729b0a22013-07-02 11:57:33 -0400349 getNamePaint(first_plan));
alisiondf1dac92013-06-27 17:35:53 -0400350
alision2cb99562013-05-30 17:02:20 -0400351 }
352
353 } catch (IndexOutOfBoundsException e) {
354 Log.e(TAG, e.toString());
355 }
356 }
357 }
alision34673e62013-06-25 14:40:07 -0400358
359 }
360
361 private Paint getNamePaint(Bubble b) {
alision50fa0722013-06-25 17:29:44 -0400362 if (b.expanded) {
363 white_name_paint.setTextSize(15 * b.target_scale * textDensity);
alision34673e62013-06-25 14:40:07 -0400364 return white_name_paint;
alision50fa0722013-06-25 17:29:44 -0400365 }
366 black_name_paint.setTextSize(18 * b.target_scale * textDensity);
alision34673e62013-06-25 14:40:07 -0400367 return black_name_paint;
alision2cb99562013-05-30 17:02:20 -0400368 }
Adrien Béraud04463092013-05-06 14:17:22 +1000369
alisione38001f2013-06-04 14:14:39 -0400370 @Override
371 public boolean onTouch(View v, MotionEvent event) {
Alexandre Lision6deda412013-09-25 13:21:22 -0400372 // Log.w(TAG, "onTouch " + event.getAction());
alisione38001f2013-06-04 14:14:39 -0400373
374 int action = event.getActionMasked();
375
376 if (action == MotionEvent.ACTION_UP) {
377 if (thread.suspendFlag) {
378 Log.i(TAG, "Relaunch drawing thread");
379 thread.setPaused(false);
380 }
381
382 List<Bubble> bubbles = model.getBubbles();
383 final int n_bubbles = bubbles.size();
384 for (int i = 0; i < n_bubbles; i++) {
385 Bubble b = bubbles.get(i);
386 if (b.dragged) {
387 b.dragged = false;
388 b.target_scale = 1.f;
Alexandre Lisionfdef8852013-09-24 13:32:38 -0400389 if (b.isOnBorder(model.width, model.height) && !b.expanded) {
Alexandre Lision0edf18c2013-09-23 17:35:50 -0400390 b.markedToDie = true;
391 ((CallActivity) callback.getActivity()).onCallEnded(b.associated_call);
392 }
alisione38001f2013-06-04 14:14:39 -0400393 }
394 }
395 dragging_bubble = false;
396 } else if (action != MotionEvent.ACTION_DOWN && !isDraggingBubble() && !thread.suspendFlag) {
397
398 Log.i(TAG, "Not dragging thread should be stopped");
399 thread.setPaused(true);
400 // thread.holdDrawing();
401 }
402
403 return gDetector.onTouchEvent(event);
404 }
405
alision34673e62013-06-25 14:40:07 -0400406 private Bubble getExpandedBubble() {
407 List<Bubble> bubbles = model.getBubbles();
408 final int n_bubbles = bubbles.size();
409 for (int i = 0; i < n_bubbles; i++) {
410 Bubble b = bubbles.get(i);
411 if (b.expanded) {
412 return b;
413 }
414 }
415 return null;
416 }
alision2ec64f92013-06-17 17:28:58 -0400417
alisiondf1dac92013-06-27 17:35:53 -0400418 public void restartDrawing() {
419 if (thread != null && thread.suspendFlag) {
420 Log.i(TAG, "Relaunch drawing thread");
421 thread.setPaused(false);
422 }
423 }
424
425 public void setFragment(CallFragment callFragment) {
426 callback = callFragment;
427
428 }
429
430 public void stopThread() {
431 if (thread != null && thread.suspendFlag) {
432 Log.i(TAG, "Stop drawing thread");
433 thread.setRunning(false);
434 thread.setPaused(false);
435 }
436
437 }
438
alision58356b72013-06-03 17:13:36 -0400439 class MyOnGestureListener implements OnGestureListener {
440 @Override
441 public boolean onDown(MotionEvent event) {
442 List<Bubble> bubbles = model.getBubbles();
443 final int n_bubbles = bubbles.size();
alision2ec64f92013-06-17 17:28:58 -0400444 Bubble expand = getExpandedBubble();
alision34673e62013-06-25 14:40:07 -0400445 if (expand != null) {
446 if (!expand.intersects(event.getX(), event.getY())) {
447 expand.retract();
448 } else {
Alexandre Lision6deda412013-09-25 13:21:22 -0400449 // Log.d("Main", "getAction");
alision50fa0722013-06-25 17:29:44 -0400450 switch (expand.getAction(event.getX(), event.getY())) {
451 case 0:
452 expand.retract();
453 break;
454 case 1:
alisiondf1dac92013-06-27 17:35:53 -0400455 if (expand.associated_call.isOnHold()) {
456 ((CallActivity) callback.getActivity()).onCallResumed(expand.associated_call);
457 } else {
458 ((CallActivity) callback.getActivity()).onCallSuspended(expand.associated_call);
459 }
460
alision50fa0722013-06-25 17:29:44 -0400461 break;
462 case 2:
463 Log.d("Main", "onRecordCall");
464 ((CallActivity) callback.getActivity()).onRecordCall(expand.associated_call);
465 break;
466 case 3:
Alexandre Lision2b237922013-09-09 16:23:02 -0400467 callback.makeTransfer(expand);
alision50fa0722013-06-25 17:29:44 -0400468 break;
alision34673e62013-06-25 14:40:07 -0400469 }
470 }
471 return true;
alision2ec64f92013-06-17 17:28:58 -0400472 }
Alexandre Lision6deda412013-09-25 13:21:22 -0400473 // Log.d("Main", "onDown");
alision58356b72013-06-03 17:13:36 -0400474 for (int i = 0; i < n_bubbles; i++) {
475 Bubble b = bubbles.get(i);
alision34673e62013-06-25 14:40:07 -0400476 if (b.intersects(event.getX(), event.getY()) && !b.expanded) {
alision58356b72013-06-03 17:13:36 -0400477 b.dragged = true;
478 b.last_drag = System.nanoTime();
479 b.setPos(event.getX(), event.getY());
480 b.target_scale = .8f;
481 dragging_bubble = true;
482 }
483 }
484 return true;
485 }
alision2ec64f92013-06-17 17:28:58 -0400486
alision58356b72013-06-03 17:13:36 -0400487 @Override
488 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
Alexandre Lision6deda412013-09-25 13:21:22 -0400489 // Log.d("Main", "onFling");
alision58356b72013-06-03 17:13:36 -0400490 return true;
491 }
492
493 @Override
494 public void onLongPress(MotionEvent e) {
Alexandre Lision6deda412013-09-25 13:21:22 -0400495 // Log.d("Main", "onLongPress");
alision2ec64f92013-06-17 17:28:58 -0400496 if (isDraggingBubble()) {
497 Bubble b = getDraggedBubble(e);
alision729b0a22013-07-02 11:57:33 -0400498 b.expand();
alision2ec64f92013-06-17 17:28:58 -0400499 }
500 }
501
alision2ec64f92013-06-17 17:28:58 -0400502 private Bubble getDraggedBubble(MotionEvent e) {
503 List<Bubble> bubbles = model.getBubbles();
504 final int n_bubbles = bubbles.size();
505 for (int i = 0; i < n_bubbles; i++) {
506 Bubble b = bubbles.get(i);
507 if (b.intersects(e.getX(), e.getY())) {
508 return b;
509 }
510 }
511 return null;
alision58356b72013-06-03 17:13:36 -0400512 }
513
514 @Override
515 public boolean onScroll(MotionEvent e1, MotionEvent event, float distanceX, float distanceY) {
Alexandre Lision6deda412013-09-25 13:21:22 -0400516 // Log.d("Main", "onScroll");
alision58356b72013-06-03 17:13:36 -0400517 List<Bubble> bubbles = model.getBubbles();
518 final int n_bubbles = bubbles.size();
519 long now = System.nanoTime();
520 for (int i = 0; i < n_bubbles; i++) {
521 Bubble b = bubbles.get(i);
522 if (b.dragged) {
523 float x = event.getX(), y = event.getY();
524 float dt = (float) ((now - b.last_drag) / 1000000000.);
525 float dx = x - b.getPosX(), dy = y - b.getPosY();
526 b.last_drag = now;
alision58356b72013-06-03 17:13:36 -0400527 b.setPos(event.getX(), event.getY());
alision58356b72013-06-03 17:13:36 -0400528 b.speed.x = dx / dt;
529 b.speed.y = dy / dt;
alision58356b72013-06-03 17:13:36 -0400530 // }
531 return true;
532 }
533 }
534 return true;
535 }
536
537 @Override
538 public void onShowPress(MotionEvent e) {
Alexandre Lision6deda412013-09-25 13:21:22 -0400539 // Log.d("Main", "onShowPress");
alision58356b72013-06-03 17:13:36 -0400540
541 }
542
543 @Override
544 public boolean onSingleTapUp(MotionEvent e) {
Alexandre Lision6deda412013-09-25 13:21:22 -0400545 // Log.d("Main", "onSingleTapUp");
alision58356b72013-06-03 17:13:36 -0400546 return true;
547 }
548 }
alisionfe9cf712013-05-03 17:26:08 -0400549}