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