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