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