alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 1 | /*
|
Alexandre Lision | c1024c0 | 2014-01-06 11:12:53 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
|
alision | cc7bb42 | 2013-06-06 15:31:39 -0400 | [diff] [blame] | 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 Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 33 | package org.sflphone.model;
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 34 |
|
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 35 | import java.util.List;
|
| 36 |
|
Alexandre Lision | 2cd1ce4 | 2014-01-07 17:18:58 -0500 | [diff] [blame] | 37 | import android.opengl.GLSurfaceView;
|
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 38 | import org.sflphone.R;
|
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 39 | import org.sflphone.fragments.CallFragment;
|
| 40 |
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 41 | import android.content.Context;
|
| 42 | import android.graphics.Canvas;
|
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 43 | import android.graphics.Paint;
|
Adrien Béraud | 6bbce91 | 2013-05-24 00:48:13 +1000 | [diff] [blame] | 44 | import android.graphics.Paint.Align;
|
Alexandre Lision | 23628c1 | 2013-09-24 11:17:05 -0400 | [diff] [blame] | 45 | import android.graphics.Paint.Style;
|
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 46 | import android.graphics.PixelFormat;
|
Alexandre Lision | 940a9db | 2013-11-19 17:12:02 -0500 | [diff] [blame] | 47 | import android.graphics.PorterDuff.Mode;
|
| 48 | import android.graphics.PorterDuffXfermode;
|
Alexandre Lision | 0edf18c | 2013-09-23 17:35:50 -0400 | [diff] [blame] | 49 | import android.graphics.RectF;
|
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 50 | import android.os.RemoteException;
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 51 | import android.util.AttributeSet;
|
| 52 | import android.util.Log;
|
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 53 | import android.view.GestureDetector;
|
| 54 | import android.view.GestureDetector.OnGestureListener;
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 55 | import android.view.MotionEvent;
|
Adrien Béraud | 0446309 | 2013-05-06 14:17:22 +1000 | [diff] [blame] | 56 | import android.view.SurfaceHolder;
|
| 57 | import android.view.SurfaceView;
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 58 | import android.view.View;
|
Adrien Béraud | 0446309 | 2013-05-06 14:17:22 +1000 | [diff] [blame] | 59 | import android.view.View.OnTouchListener;
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 60 |
|
Alexandre Lision | 2cd1ce4 | 2014-01-07 17:18:58 -0500 | [diff] [blame] | 61 | public class BubblesView extends GLSurfaceView implements SurfaceHolder.Callback, OnTouchListener {
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 62 | private static final String TAG = BubblesView.class.getSimpleName();
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 63 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 64 | private BubblesThread thread = null;
|
| 65 | private BubbleModel model;
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 66 |
|
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 67 | 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éraud | 6bbce91 | 2013-05-24 00:48:13 +1000 | [diff] [blame] | 69 |
|
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 70 | private GestureDetector gDetector;
|
| 71 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 72 | private float density;
|
| 73 | private float textDensity;
|
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 74 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 75 | private boolean dragging_bubble = false;
|
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 76 |
|
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 77 | private CallFragment callback;
|
| 78 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 79 | public BubblesView(Context context, AttributeSet attrs) {
|
| 80 | super(context, attrs);
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 81 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 82 | density = getResources().getDisplayMetrics().density;
|
| 83 | textDensity = getResources().getDisplayMetrics().scaledDensity;
|
Adrien Béraud | 6bbce91 | 2013-05-24 00:48:13 +1000 | [diff] [blame] | 84 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 85 | SurfaceHolder holder = getHolder();
|
| 86 | holder.addCallback(this);
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 87 |
|
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 88 | this.setZOrderOnTop(true); // necessary
|
| 89 | this.getHolder().setFormat(PixelFormat.TRANSLUCENT);
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 90 | // create thread only; it's started in surfaceCreated()
|
| 91 | createThread();
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 92 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 93 | setOnTouchListener(this);
|
| 94 | setFocusable(true);
|
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 95 |
|
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 96 | 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);
|
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 103 |
|
| 104 | gDetector = new GestureDetector(getContext(), new MyOnGestureListener());
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 105 | }
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 106 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 107 | private void createThread() {
|
| 108 | if (thread != null)
|
| 109 | return;
|
Alexandre Lision | f30ff85 | 2013-12-09 17:08:40 -0500 | [diff] [blame] | 110 | thread = new BubblesThread(getHolder(), getContext());
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 111 | if (model != null)
|
| 112 | thread.setModel(model);
|
| 113 | }
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 114 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 115 | public void setModel(BubbleModel model) {
|
| 116 | this.model = model;
|
| 117 | thread.setModel(model);
|
| 118 | }
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 119 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 120 | /*
|
| 121 | * @Override public void onWindowFocusChanged(boolean hasWindowFocus) { if (!hasWindowFocus) { thread.pause(); } }
|
| 122 | */
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 123 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 124 | @Override
|
| 125 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
| 126 | Log.w(TAG, "surfaceChanged " + width + "-" + height);
|
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 127 | if (height < model.height) // probably showing the keyboard, don't move!
|
Alexandre Lision | 84208a3 | 2013-09-25 13:18:37 -0400 | [diff] [blame] | 128 | return;
|
| 129 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 130 | thread.setSurfaceSize(width, height);
|
| 131 | }
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 132 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 133 | /*
|
| 134 | * Callback invoked when the Surface has been created and is ready to be used.
|
| 135 | */
|
| 136 | @Override
|
| 137 | public void surfaceCreated(SurfaceHolder holder) {
|
| 138 | // start the thread here so that we don't busy-wait in run()
|
| 139 | // waiting for the surface to be created
|
| 140 | createThread();
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 141 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 142 | Log.w(TAG, "surfaceCreated");
|
| 143 | thread.setRunning(true);
|
| 144 | thread.start();
|
| 145 | }
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 146 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 147 | /*
|
| 148 | * Callback invoked when the Surface has been destroyed and must no longer be touched. WARNING: after this method returns, the Surface/Canvas must
|
| 149 | * never be touched again!
|
| 150 | */
|
| 151 | @Override
|
| 152 | public void surfaceDestroyed(SurfaceHolder holder) {
|
| 153 | // we have to tell thread to shut down & wait for it to finish, or else
|
| 154 | // it might touch the Surface after we return and explode
|
| 155 | Log.w(TAG, "surfaceDestroyed");
|
| 156 | boolean retry = true;
|
| 157 | thread.setRunning(false);
|
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 158 | thread.setPaused(false);
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 159 | while (retry) {
|
| 160 | try {
|
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 161 | Log.w(TAG, "joining...");
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 162 | thread.join();
|
| 163 | retry = false;
|
| 164 | } catch (InterruptedException e) {
|
| 165 | }
|
| 166 | }
|
alision | 1005ba1 | 2013-06-19 13:52:44 -0400 | [diff] [blame] | 167 | Log.w(TAG, "done");
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 168 | thread = null;
|
| 169 | }
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 170 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 171 | public boolean isDraggingBubble() {
|
| 172 | return dragging_bubble;
|
| 173 | }
|
Adrien Béraud | c9c424d | 2013-05-30 17:47:35 +1000 | [diff] [blame] | 174 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 175 | class BubblesThread extends Thread {
|
| 176 | private boolean running = false;
|
| 177 | private SurfaceHolder surfaceHolder;
|
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 178 | public Boolean suspendFlag = false;
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 179 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 180 | BubbleModel model = null;
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 181 |
|
Alexandre Lision | f30ff85 | 2013-12-09 17:08:40 -0500 | [diff] [blame] | 182 | public BubblesThread(SurfaceHolder holder, Context context) {
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 183 | surfaceHolder = holder;
|
| 184 | }
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 185 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 186 | public void setModel(BubbleModel model) {
|
| 187 | this.model = model;
|
| 188 | }
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 189 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 190 | @Override
|
| 191 | public void run() {
|
| 192 | while (running) {
|
| 193 | Canvas c = null;
|
| 194 | try {
|
Adrien Béraud | 7ed23dc | 2013-05-06 16:27:24 +1000 | [diff] [blame] | 195 |
|
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 196 | if (suspendFlag) {
|
| 197 | synchronized (this) {
|
| 198 | while (suspendFlag) {
|
| 199 | try {
|
| 200 | wait();
|
| 201 | } catch (InterruptedException e) {
|
| 202 | // TODO Auto-generated catch block
|
| 203 | e.printStackTrace();
|
| 204 | }
|
| 205 | }
|
| 206 | }
|
| 207 | } else {
|
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 208 | c = surfaceHolder.lockCanvas(null);
|
Adrien Béraud | 7ed23dc | 2013-05-06 16:27:24 +1000 | [diff] [blame] | 209 |
|
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 210 | // for the case the surface is destroyed while already in the loop
|
| 211 | if (c == null || model == null)
|
| 212 | continue;
|
| 213 |
|
| 214 | synchronized (surfaceHolder) {
|
| 215 | // Log.w(TAG, "Thread doDraw");
|
| 216 | model.update();
|
| 217 | doDraw(c);
|
| 218 | }
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 219 | }
|
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 220 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 221 | } finally {
|
| 222 | if (c != null)
|
| 223 | surfaceHolder.unlockCanvasAndPost(c);
|
| 224 | }
|
| 225 | }
|
| 226 | }
|
Adrien Béraud | 0446309 | 2013-05-06 14:17:22 +1000 | [diff] [blame] | 227 |
|
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 228 | public void setPaused(boolean wantToPause) {
|
| 229 | synchronized (this) {
|
| 230 | suspendFlag = wantToPause;
|
| 231 | notify();
|
| 232 | }
|
| 233 | }
|
| 234 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 235 | public void setRunning(boolean b) {
|
| 236 | running = b;
|
| 237 | }
|
Adrien Béraud | 0446309 | 2013-05-06 14:17:22 +1000 | [diff] [blame] | 238 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 239 | public void setSurfaceSize(int width, int height) {
|
| 240 | synchronized (surfaceHolder) {
|
| 241 | if (model != null) {
|
| 242 | model.width = width;
|
| 243 | model.height = height;
|
| 244 | }
|
| 245 | }
|
| 246 | }
|
Adrien Béraud | 0446309 | 2013-05-06 14:17:22 +1000 | [diff] [blame] | 247 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 248 | /**
|
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 249 | * got multiple IndexOutOfBoundsException, when switching calls. //FIXME
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 250 | *
|
| 251 | * @param canvas
|
| 252 | */
|
| 253 | private void doDraw(Canvas canvas) {
|
Adrien Béraud | 0446309 | 2013-05-06 14:17:22 +1000 | [diff] [blame] | 254 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 255 | synchronized (model) {
|
| 256 | List<Bubble> bubbles = model.getBubbles();
|
| 257 | List<Attractor> attractors = model.getAttractors();
|
Alexandre Lision | 0edf18c | 2013-09-23 17:35:50 -0400 | [diff] [blame] | 258 |
|
| 259 | Paint tryMe = new Paint();
|
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 260 |
|
Alexandre Lision | 940a9db | 2013-11-19 17:12:02 -0500 | [diff] [blame] | 261 | Paint paint = new Paint();
|
| 262 | paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));
|
| 263 | canvas.drawPaint(paint);
|
| 264 | paint.setXfermode(new PorterDuffXfermode(Mode.SRC));
|
Alexandre Lision | 0edf18c | 2013-09-23 17:35:50 -0400 | [diff] [blame] | 265 |
|
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 266 | // canvas.drawColor(Color.LTGRAY);
|
Alexandre Lision | 0edf18c | 2013-09-23 17:35:50 -0400 | [diff] [blame] | 267 |
|
| 268 | if (dragging_bubble) {
|
Alexandre Lision | 0edf18c | 2013-09-23 17:35:50 -0400 | [diff] [blame] | 269 | Paint p = new Paint();
|
| 270 | p.setDither(true);
|
Alexandre Lision | 23628c1 | 2013-09-24 11:17:05 -0400 | [diff] [blame] | 271 | p.setColor(getResources().getColor(R.color.holo_red_light));
|
Alexandre Lision | 23628c1 | 2013-09-24 11:17:05 -0400 | [diff] [blame] | 272 | p.setStyle(Style.STROKE);
|
Alexandre Lision | 23628c1 | 2013-09-24 11:17:05 -0400 | [diff] [blame] | 273 | p.setStrokeWidth(20);
|
Alexandre Lision | 23628c1 | 2013-09-24 11:17:05 -0400 | [diff] [blame] | 274 | canvas.drawRect(new RectF(10, 10, model.width - 10, model.height - 10), p);
|
Alexandre Lision | 0edf18c | 2013-09-23 17:35:50 -0400 | [diff] [blame] | 275 | }
|
| 276 |
|
| 277 | tryMe.setStyle(Paint.Style.STROKE);
|
| 278 | tryMe.setColor(getResources().getColor(R.color.darker_gray));
|
| 279 | tryMe.setXfermode(null);
|
| 280 | canvas.drawCircle(model.width / 2, model.height / 2, model.width / 2 - getResources().getDimension(R.dimen.bubble_size), tryMe);
|
| 281 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 282 | try {
|
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 283 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 284 | for (int i = 0, n = attractors.size(); i < n; i++) {
|
| 285 | Attractor a = attractors.get(i);
|
| 286 | canvas.drawBitmap(a.getBitmap(), null, a.getBounds(), null);
|
| 287 | }
|
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 288 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 289 | for (int i = 0, n = bubbles.size(); i < n; i++) {
|
| 290 | Bubble b = bubbles.get(i);
|
Alexandre Lision | 0edf18c | 2013-09-23 17:35:50 -0400 | [diff] [blame] | 291 | if (b.expanded) {
|
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 292 | continue;
|
| 293 | }
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 294 | canvas.drawBitmap(b.getBitmap(), null, b.getBounds(), null);
|
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 295 | canvas.drawText(b.getName(), b.getPosX(), (float) (b.getPosY() - b.getRetractedRadius() * 1.2 * density), getNamePaint(b));
|
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 296 | }
|
Alexandre Lision | 0edf18c | 2013-09-23 17:35:50 -0400 | [diff] [blame] | 297 |
|
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 298 | Bubble first_plan = getExpandedBubble();
|
| 299 | if (first_plan != null) {
|
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 300 |
|
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 301 | if (first_plan.getDrawerBitmap() != null) {
|
| 302 | canvas.drawBitmap(first_plan.getDrawerBitmap(), null, first_plan.getDrawerBounds(), null);
|
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 303 | }
|
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 304 | canvas.drawBitmap(first_plan.getBitmap(), null, first_plan.getBounds(), null);
|
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 305 | // canvas.drawText(first_plan.associated_call.getContact().getmDisplayName(), first_plan.getPosX(),
|
| 306 | // (float) (first_plan.getPosY() - first_plan.getRetractedRadius() * 1.2 * density), getNamePaint(first_plan));
|
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 307 |
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 308 | }
|
| 309 |
|
| 310 | } catch (IndexOutOfBoundsException e) {
|
| 311 | Log.e(TAG, e.toString());
|
| 312 | }
|
| 313 | }
|
| 314 | }
|
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 315 |
|
| 316 | }
|
| 317 |
|
| 318 | private Paint getNamePaint(Bubble b) {
|
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame] | 319 | if (b.expanded) {
|
| 320 | white_name_paint.setTextSize(15 * b.target_scale * textDensity);
|
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 321 | return white_name_paint;
|
alision | 50fa072 | 2013-06-25 17:29:44 -0400 | [diff] [blame] | 322 | }
|
| 323 | black_name_paint.setTextSize(18 * b.target_scale * textDensity);
|
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 324 | return black_name_paint;
|
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 325 | }
|
Adrien Béraud | 0446309 | 2013-05-06 14:17:22 +1000 | [diff] [blame] | 326 |
|
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 327 | @Override
|
| 328 | public boolean onTouch(View v, MotionEvent event) {
|
Alexandre Lision | 6deda41 | 2013-09-25 13:21:22 -0400 | [diff] [blame] | 329 | // Log.w(TAG, "onTouch " + event.getAction());
|
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 330 |
|
| 331 | int action = event.getActionMasked();
|
| 332 |
|
Alexandre Lision | 1888bf3 | 2013-10-31 09:51:41 -0400 | [diff] [blame] | 333 | if (gDetector.onTouchEvent(event))
|
| 334 | return true;
|
| 335 |
|
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 336 | if (action == MotionEvent.ACTION_UP) {
|
| 337 | if (thread.suspendFlag) {
|
| 338 | Log.i(TAG, "Relaunch drawing thread");
|
| 339 | thread.setPaused(false);
|
| 340 | }
|
| 341 |
|
Alexandre Lision | 5cd659e | 2013-10-29 13:18:23 -0400 | [diff] [blame] | 342 | Bubble expand = getExpandedBubble();
|
| 343 | if (expand != null) {
|
Alexandre Lision | 5cd659e | 2013-10-29 13:18:23 -0400 | [diff] [blame] | 344 | switch (expand.getDrawer().getAction(event.getX(), event.getY())) {
|
| 345 | case Bubble.actions.OUT_OF_BOUNDS:
|
| 346 | expand.retract();
|
| 347 | break;
|
| 348 | case Bubble.actions.HOLD:
|
| 349 |
|
| 350 | try {
|
| 351 | if (expand.getHoldStatus()) {
|
| 352 |
|
| 353 | if (expand.isConference())
|
| 354 | callback.mCallbacks.getService().unholdConference(expand.getCallID());
|
| 355 | else
|
| 356 | callback.mCallbacks.getService().unhold(expand.getCallID());
|
| 357 | } else {
|
| 358 | if (expand.isConference())
|
| 359 | callback.mCallbacks.getService().holdConference(expand.getCallID());
|
| 360 | else
|
| 361 | callback.mCallbacks.getService().hold(expand.getCallID());
|
| 362 |
|
| 363 | }
|
| 364 | } catch (Exception e) {
|
| 365 | e.printStackTrace();
|
| 366 | }
|
| 367 |
|
| 368 | return true;
|
| 369 | case Bubble.actions.RECORD:
|
| 370 | try {
|
Alexandre Lision | 3874e55 | 2013-11-04 17:20:12 -0500 | [diff] [blame] | 371 | boolean isRecording = callback.mCallbacks.getService().toggleRecordingCall(expand.getCallID());
|
| 372 | ((BubbleUser) expand).associated_call.setRecording(isRecording);
|
Alexandre Lision | 5cd659e | 2013-10-29 13:18:23 -0400 | [diff] [blame] | 373 | } catch (RemoteException e1) {
|
| 374 | e1.printStackTrace();
|
| 375 | }
|
| 376 | return true;
|
| 377 | case Bubble.actions.MESSAGE:
|
| 378 | // TODO
|
| 379 | return true;
|
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 380 | case Bubble.actions.MUTE:
|
Alexandre Lision | c9fca9e | 2013-11-08 15:21:18 -0500 | [diff] [blame] | 381 | try {
|
| 382 | callback.mCallbacks.getService().setMuted(!((BubbleUser) expand).getMute());
|
| 383 | ((BubbleUser) expand).toggleMute();
|
| 384 | } catch (RemoteException e1) {
|
| 385 | e1.printStackTrace();
|
| 386 | }
|
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 387 | return true;
|
Alexandre Lision | 5cd659e | 2013-10-29 13:18:23 -0400 | [diff] [blame] | 388 | case Bubble.actions.HANGUP:
|
| 389 | try {
|
| 390 | if (expand.isConference())
|
| 391 | callback.mCallbacks.getService().hangUpConference(expand.getCallID());
|
| 392 | else
|
| 393 | callback.mCallbacks.getService().hangUp(expand.getCallID());
|
| 394 | } catch (RemoteException e) {
|
| 395 | e.printStackTrace();
|
| 396 | }
|
| 397 | return true;
|
| 398 |
|
| 399 | case Bubble.actions.TRANSFER:
|
| 400 | callback.makeTransfer((BubbleContact) expand);
|
| 401 | return true;
|
| 402 | case Bubble.actions.NOTHING:
|
| 403 | break;
|
| 404 | }
|
Alexandre Lision | 5cd659e | 2013-10-29 13:18:23 -0400 | [diff] [blame] | 405 |
|
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 406 | }
|
Alexandre Lision | 5cd659e | 2013-10-29 13:18:23 -0400 | [diff] [blame] | 407 |
|
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 408 | List<Bubble> bubbles = model.getBubbles();
|
| 409 | final int n_bubbles = bubbles.size();
|
| 410 | for (int i = 0; i < n_bubbles; i++) {
|
| 411 | Bubble b = bubbles.get(i);
|
| 412 | if (b.dragged) {
|
| 413 | b.dragged = false;
|
| 414 | b.target_scale = 1.f;
|
Alexandre Lision | fdef885 | 2013-09-24 13:32:38 -0400 | [diff] [blame] | 415 | if (b.isOnBorder(model.width, model.height) && !b.expanded) {
|
Alexandre Lision | 0edf18c | 2013-09-23 17:35:50 -0400 | [diff] [blame] | 416 | b.markedToDie = true;
|
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 417 |
|
| 418 | try {
|
| 419 | if (b.isConference())
|
| 420 | callback.mCallbacks.getService().hangUpConference(b.getCallID());
|
| 421 | else
|
| 422 | callback.mCallbacks.getService().hangUp(b.getCallID());
|
| 423 |
|
| 424 | } catch (RemoteException e) {
|
| 425 | e.printStackTrace();
|
| 426 | }
|
Alexandre Lision | 0edf18c | 2013-09-23 17:35:50 -0400 | [diff] [blame] | 427 | }
|
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 428 | }
|
| 429 | }
|
| 430 | dragging_bubble = false;
|
| 431 | } else if (action != MotionEvent.ACTION_DOWN && !isDraggingBubble() && !thread.suspendFlag) {
|
| 432 |
|
| 433 | Log.i(TAG, "Not dragging thread should be stopped");
|
| 434 | thread.setPaused(true);
|
| 435 | // thread.holdDrawing();
|
| 436 | }
|
| 437 |
|
Alexandre Lision | 1888bf3 | 2013-10-31 09:51:41 -0400 | [diff] [blame] | 438 | return true;
|
alision | e38001f | 2013-06-04 14:14:39 -0400 | [diff] [blame] | 439 | }
|
| 440 |
|
alision | 34673e6 | 2013-06-25 14:40:07 -0400 | [diff] [blame] | 441 | private Bubble getExpandedBubble() {
|
| 442 | List<Bubble> bubbles = model.getBubbles();
|
| 443 | final int n_bubbles = bubbles.size();
|
| 444 | for (int i = 0; i < n_bubbles; i++) {
|
| 445 | Bubble b = bubbles.get(i);
|
| 446 | if (b.expanded) {
|
| 447 | return b;
|
| 448 | }
|
| 449 | }
|
| 450 | return null;
|
| 451 | }
|
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 452 |
|
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 453 | public void restartDrawing() {
|
| 454 | if (thread != null && thread.suspendFlag) {
|
| 455 | Log.i(TAG, "Relaunch drawing thread");
|
| 456 | thread.setPaused(false);
|
| 457 | }
|
| 458 | }
|
| 459 |
|
| 460 | public void setFragment(CallFragment callFragment) {
|
| 461 | callback = callFragment;
|
| 462 |
|
| 463 | }
|
| 464 |
|
| 465 | public void stopThread() {
|
| 466 | if (thread != null && thread.suspendFlag) {
|
| 467 | Log.i(TAG, "Stop drawing thread");
|
Alexandre Lision | 666b377 | 2013-10-28 17:42:48 -0400 | [diff] [blame] | 468 | thread.setPaused(true);
|
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 469 | }
|
| 470 |
|
| 471 | }
|
| 472 |
|
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 473 | class MyOnGestureListener implements OnGestureListener {
|
| 474 | @Override
|
| 475 | public boolean onDown(MotionEvent event) {
|
| 476 | List<Bubble> bubbles = model.getBubbles();
|
Alexandre Lision | 1888bf3 | 2013-10-31 09:51:41 -0400 | [diff] [blame] | 477 |
|
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 478 | Bubble target = getExpandedBubble();
|
Alexandre Lision | 1888bf3 | 2013-10-31 09:51:41 -0400 | [diff] [blame] | 479 | if (target != null) {
|
Alexandre Lision | 8fdcf2b | 2013-10-30 16:06:51 -0400 | [diff] [blame] | 480 | target.onDown(event);
|
| 481 | return true;
|
| 482 | }
|
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 483 |
|
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 484 | for (int i = 0; i < bubbles.size(); i++) {
|
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 485 | Bubble b = bubbles.get(i);
|
Alexandre Lision | 1888bf3 | 2013-10-31 09:51:41 -0400 | [diff] [blame] | 486 | if (b.onDown(event))
|
| 487 | dragging_bubble = true;
|
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 488 | }
|
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 489 |
|
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 490 | return true;
|
| 491 | }
|
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 492 |
|
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 493 | @Override
|
| 494 | public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
Alexandre Lision | 6deda41 | 2013-09-25 13:21:22 -0400 | [diff] [blame] | 495 | // Log.d("Main", "onFling");
|
Alexandre Lision | 1888bf3 | 2013-10-31 09:51:41 -0400 | [diff] [blame] | 496 | return false;
|
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 497 | }
|
| 498 |
|
| 499 | @Override
|
| 500 | public void onLongPress(MotionEvent e) {
|
Alexandre Lision | 6deda41 | 2013-09-25 13:21:22 -0400 | [diff] [blame] | 501 | // Log.d("Main", "onLongPress");
|
Alexandre Lision | 1888bf3 | 2013-10-31 09:51:41 -0400 | [diff] [blame] | 502 |
|
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 503 | }
|
| 504 |
|
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 505 | private Bubble getDraggedBubble(MotionEvent e) {
|
| 506 | List<Bubble> bubbles = model.getBubbles();
|
| 507 | final int n_bubbles = bubbles.size();
|
| 508 | for (int i = 0; i < n_bubbles; i++) {
|
| 509 | Bubble b = bubbles.get(i);
|
| 510 | if (b.intersects(e.getX(), e.getY())) {
|
| 511 | return b;
|
| 512 | }
|
| 513 | }
|
| 514 | return null;
|
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 515 | }
|
| 516 |
|
| 517 | @Override
|
| 518 | public boolean onScroll(MotionEvent e1, MotionEvent event, float distanceX, float distanceY) {
|
Alexandre Lision | 6deda41 | 2013-09-25 13:21:22 -0400 | [diff] [blame] | 519 | // Log.d("Main", "onScroll");
|
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 520 | List<Bubble> bubbles = model.getBubbles();
|
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 521 |
|
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 522 | long now = System.nanoTime();
|
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 523 | for (int i = 0; i < bubbles.size(); i++) {
|
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 524 | Bubble b = bubbles.get(i);
|
| 525 | if (b.dragged) {
|
| 526 | float x = event.getX(), y = event.getY();
|
| 527 | float dt = (float) ((now - b.last_drag) / 1000000000.);
|
| 528 | float dx = x - b.getPosX(), dy = y - b.getPosY();
|
| 529 | b.last_drag = now;
|
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 530 | b.setPos(event.getX(), event.getY());
|
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 531 | b.speed.x = dx / dt;
|
| 532 | b.speed.y = dy / dt;
|
Alexandre Lision | d9c3f7f | 2013-10-30 15:20:55 -0400 | [diff] [blame] | 533 |
|
Alexandre Lision | 1888bf3 | 2013-10-31 09:51:41 -0400 | [diff] [blame] | 534 | return false;
|
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 535 | }
|
| 536 | }
|
| 537 | return true;
|
| 538 | }
|
| 539 |
|
| 540 | @Override
|
| 541 | public void onShowPress(MotionEvent e) {
|
Alexandre Lision | 6deda41 | 2013-09-25 13:21:22 -0400 | [diff] [blame] | 542 | // Log.d("Main", "onShowPress");
|
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 543 |
|
| 544 | }
|
| 545 |
|
| 546 | @Override
|
| 547 | public boolean onSingleTapUp(MotionEvent e) {
|
Alexandre Lision | 1888bf3 | 2013-10-31 09:51:41 -0400 | [diff] [blame] | 548 | if (isDraggingBubble() && callback.getConference().isOnGoing()) {
|
| 549 | Bubble b = getDraggedBubble(e);
|
| 550 | b.expand(model.width, model.height);
|
Alexandre Lision | 1a68257 | 2013-11-01 11:21:17 -0400 | [diff] [blame] | 551 | dragging_bubble = false;
|
Alexandre Lision | 1888bf3 | 2013-10-31 09:51:41 -0400 | [diff] [blame] | 552 | }
|
| 553 | return false;
|
| 554 |
|
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 555 | }
|
| 556 | }
|
alision | fe9cf71 | 2013-05-03 17:26:08 -0400 | [diff] [blame] | 557 | }
|