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