Project

General

Profile

« Previous | Next » 

Revision e52efe17

Added by Leszek Koltunski over 5 years ago

Improve the Dynamic app.

View differences:

src/main/java/org/distorted/examples/dynamic/DynamicActivity.java
46 46
    private int mDim, mMode;
47 47

  
48 48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

  
49 50
    @Override
50 51
    protected void onCreate(Bundle savedState)
51 52
      {
......
87 88
      ArrayAdapter<String> adapterMode = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, modes );
88 89
      adapterMode.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
89 90
      modeSpinner.setAdapter(adapterMode);
91
      modeSpinner.setSelection(0);
90 92

  
91 93
      if( savedState==null )
92 94
        {
......
103 105
      }
104 106

  
105 107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

  
106 109
    @Override
107 110
    protected void onResume() 
108 111
      {
109 112
      super.onResume();
110 113
      
111
      GLSurfaceView view = findViewById(R.id.dynamicSurfaceView);
112
      view.onResume();
114
      GLSurfaceView v1 = findViewById(R.id.dynamicSurfaceView);
115
      v1.onResume();
116
      DynamicSpeedSurfaceView v2 = findViewById(R.id.dynamicSpeedSurfaceView);
117
      v2.onResume();
113 118
      }
114 119

  
115 120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

  
116 122
    @Override
117 123
    protected void onPause() 
118 124
      {
119
      GLSurfaceView view = findViewById(R.id.dynamicSurfaceView);
120
      view.onPause();
125
      GLSurfaceView v1 = findViewById(R.id.dynamicSurfaceView);
126
      v1.onPause();
127
      DynamicSpeedSurfaceView v2 = findViewById(R.id.dynamicSpeedSurfaceView);
128
      v2.onPause();
121 129

  
122 130
      DistortedLibrary.onPause();
123 131
      super.onPause();
124 132
      }
125 133
    
126 134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

  
127 136
    @Override
128 137
    public void onStop()
129 138
      {
......
131 140
      }
132 141

  
133 142
///////////////////////////////////////////////////////////////////////////////////////////////////
143

  
134 144
    @Override
135 145
    public void onDestroy()
136 146
      {  
......
138 148
      super.onDestroy();
139 149
      }     
140 150

  
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152

  
153
    void setNumRedPoints(int numPoints)
154
      {
155
      DynamicSpeedSurfaceView view = findViewById(R.id.dynamicSpeedSurfaceView);
156
      view.setNumRedPoints(numPoints);
157
      }
158

  
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

  
161
    void addPoint(float x, float y)
162
      {
163
      DynamicSpeedSurfaceView view = findViewById(R.id.dynamicSpeedSurfaceView);
164
      view.addPoint(x,y);
165
      }
166

  
141 167
///////////////////////////////////////////////////////////////////////////////////////////////////
142 168

  
143 169
    public void setDim(int dim)
......
151 177

  
152 178
    public void setMode(int mode)
153 179
      {
154
      DynamicSurfaceView view = findViewById(R.id.dynamicSurfaceView);
155
      view.setMode(mode);
180
      DynamicSurfaceView v1 = findViewById(R.id.dynamicSurfaceView);
181
      v1.setMode(mode);
182
      DynamicSpeedSurfaceView v2 = findViewById(R.id.dynamicSpeedSurfaceView);
183
      v2.setMode(mode);
184

  
156 185
      mMode = mode;
157 186
      }
158 187

  
......
160 189

  
161 190
    public void Start(View v)
162 191
      {
163
      DynamicSurfaceView view = findViewById(R.id.dynamicSurfaceView);
164
      view.startDynamic();
192
      DynamicSpeedSurfaceView v2 = findViewById(R.id.dynamicSpeedSurfaceView);
193
      v2.clearPoints();
194
      DynamicSurfaceView v1 = findViewById(R.id.dynamicSurfaceView);
195
      v1.startDynamic();
165 196
      }
166 197

  
167 198
///////////////////////////////////////////////////////////////////////////////////////////////////
168 199

  
169 200
    public void Reset(View v)
170 201
      {
171
      DynamicSurfaceView view = findViewById(R.id.dynamicSurfaceView);
172
      view.resetPoints();
173
      view.stopDynamic();
202
      DynamicSurfaceView v1 = findViewById(R.id.dynamicSurfaceView);
203
      v1.resetPoints();
204
      v1.stopDynamic();
205
      DynamicSpeedSurfaceView v2 = findViewById(R.id.dynamicSpeedSurfaceView);
206
      v2.clearPoints();
174 207
      }
175 208

  
176 209
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/examples/dynamic/DynamicSpeedSurfaceView.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.examples.dynamic;
21

  
22
import android.content.Context;
23
import android.graphics.Canvas;
24
import android.graphics.Paint;
25
import android.graphics.Rect;
26
import android.util.AttributeSet;
27
import android.view.SurfaceHolder;
28
import android.view.SurfaceView;
29

  
30
import org.distorted.library.type.Dynamic;
31

  
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

  
34
class DynamicSpeedSurfaceView extends SurfaceView implements SurfaceHolder.Callback
35
{
36
    private static final int FRAME_INTERVAL = 70;
37
    private static final int NUM_POINTS     = DynamicSurfaceView.NUM_POINTS;
38

  
39
    private static boolean refreshScreen = true;
40
    private GraphicsThread mThread;
41
    private int mWidth, mHeight, mMargin;
42
    private int mMode, mNumRedPoints, mPointSize;
43
    private float mFontHeight;
44
    private Paint mPaint;
45
    private float[] mPoints = new float[2*NUM_POINTS];
46
    private int mPosition;
47
    private float mMultiplier;
48

  
49
/////////////////////////////////////////////////////////////////////////////////////////
50

  
51
    private class GraphicsThread extends Thread
52
      {
53
      private final SurfaceHolder mSurfaceHolder;
54
      private final DynamicSpeedSurfaceView mPicker;
55
      private boolean mRun = false;
56

  
57
      ///////////////////////////////////////////////////////////////////////////////////////
58

  
59
      GraphicsThread(SurfaceHolder surfaceHolder, DynamicSpeedSurfaceView p)
60
        {
61
        mSurfaceHolder = surfaceHolder;
62
        mPicker = p;
63
        }
64

  
65
      ///////////////////////////////////////////////////////////////////////////////////////
66

  
67
      void setRunning(boolean run)
68
        {
69
        mRun = run;
70
        }
71

  
72
      ///////////////////////////////////////////////////////////////////////////////////////
73

  
74
      public void run()
75
        {
76
        Canvas c;
77
        long time;
78

  
79
        while (mRun)
80
          {
81
          c = null;
82
          time = 0;
83

  
84
          if( refreshScreen )
85
            {
86
            refreshScreen=false;
87
            time = System.currentTimeMillis();
88

  
89
            try
90
              {
91
              c = mSurfaceHolder.lockCanvas(null);
92
              synchronized (mSurfaceHolder) { mPicker.render(c); }
93
              }
94
            finally
95
              {
96
              if (c != null)  mSurfaceHolder.unlockCanvasAndPost(c);
97
              }
98

  
99
            time = System.currentTimeMillis() -time;
100
            }
101

  
102
          if( time<FRAME_INTERVAL )
103
            {
104
            try { Thread.sleep(FRAME_INTERVAL-time); }
105
            catch(InterruptedException ex) {}
106
            }
107
          }
108
        }
109
      }
110

  
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

  
113
    public DynamicSpeedSurfaceView(Context context, AttributeSet attrs)
114
      {
115
      super(context,attrs);
116

  
117
      mNumRedPoints = 0;
118
      mPosition     = 0;
119

  
120
      mPaint = new Paint();
121
      mPaint.setAntiAlias(true);
122
      mPaint.setFakeBoldText(true);
123
      mPaint.setStyle(Paint.Style.FILL);
124

  
125
      clearPoints();
126

  
127
      getHolder().addCallback(this);
128
      }
129

  
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

  
132
    private void stopThread()
133
      {
134
      if( mThread!=null )
135
        {
136
        boolean retry = true;
137
        mThread.setRunning(false);
138

  
139
        while (retry)
140
          {
141
          try
142
            {
143
            mThread.join();
144
            retry = false;
145
            }
146
          catch (InterruptedException e) { android.util.Log.e( "DynamicSpeed", "Joining thread interrupted!"); }
147
          }
148

  
149
        mThread=null;
150
        }
151
      }
152

  
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154

  
155
    private void render(Canvas c)
156
      {
157
      if( c!=null )
158
        {
159
        mPaint.setColor(0xff007d00);
160
        c.drawRect(0, 0, mWidth, mHeight, mPaint);
161
        mPaint.setColor(0xff000000);
162
        c.drawText( "Speed", mWidth/2, mMargin, mPaint);
163
        drawAxis(c);
164
        drawSpeedGraph(c);
165
        drawRedPoints(c);
166
        }
167
      }
168

  
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

  
171
    private void drawAxis(Canvas c)
172
      {
173
      mPaint.setColor(0xff000000);
174

  
175
      c.drawLine( mMargin, mHeight-mMargin, mWidth-mMargin, mHeight-mMargin, mPaint);
176
      c.drawLine( mMargin, mHeight-mMargin,        mMargin,         mMargin, mPaint);
177
      }
178

  
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180

  
181
    private void drawRedPoints(Canvas c)
182
      {
183
      if( mNumRedPoints==1 )
184
        {
185
        drawRedPoint(c,"0", mMargin, mHeight-mMargin);
186
        }
187
      else if( mNumRedPoints>1 )
188
        {
189
        int len = mMode== Dynamic.MODE_LOOP ? mNumRedPoints+1 : mNumRedPoints;
190
        String label;
191
        float x;
192

  
193
        for(int curr=0; curr<len; curr++)
194
          {
195
          label = curr==mNumRedPoints ? "0" : curr+"";
196
          x = mMargin + curr*((float)(mWidth-2*mMargin))/(len-1);
197
          drawRedPoint(c,label, x, mHeight-mMargin);
198
          }
199
        }
200
      }
201

  
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203

  
204
    private void drawRedPoint(Canvas c, String label, float width, float height)
205
      {
206
      mPaint.setColor(0xffff0000);
207
      c.drawCircle( width, height, mPointSize, mPaint);
208
      mPaint.setColor(0xffffffff);
209
      c.drawText(label, width,height-mFontHeight, mPaint);
210
      }
211

  
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213

  
214
    private void drawSpeedGraph(Canvas c)
215
      {
216
      mPaint.setColor(0xffffffff);
217
      float y, highiest=0.0f;
218

  
219
      for(int i=0; i<NUM_POINTS; i++)
220
        {
221
        y = mPoints[2*i+1];
222
        c.drawCircle( mMargin+mPoints[2*i]*(mWidth-2*mMargin), mHeight-mMargin-mMultiplier*y , mPointSize*0.3f, mPaint );
223

  
224
        if( y>highiest ) highiest = y;
225
        }
226

  
227
      mMultiplier = (mHeight-2*mMargin)/highiest;
228
      }
229

  
230
///////////////////////////////////////////////////////////////////////////////////////////////////
231

  
232
    void setMode(int mode)
233
      {
234
      mMode = mode;
235
      refreshScreen = true;
236
      }
237

  
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239

  
240
    void clearPoints()
241
      {
242
      for(int i=0; i<2*NUM_POINTS; i++)
243
         {
244
         mPoints[i] = -10.0f;
245
         }
246
      refreshScreen = true;
247
      }
248

  
249
///////////////////////////////////////////////////////////////////////////////////////////////////
250

  
251
    void addPoint(float x, float y)
252
      {
253
      mPoints[2*mPosition  ] =x;
254
      mPoints[2*mPosition+1] =y;
255

  
256
      if ( ++mPosition >= NUM_POINTS ) mPosition=0;
257

  
258
      refreshScreen = true;
259
      }
260

  
261
///////////////////////////////////////////////////////////////////////////////////////////////////
262

  
263
    void setNumRedPoints(int numRedPoints)
264
      {
265
      mNumRedPoints = numRedPoints;
266
      refreshScreen = true;
267
      }
268

  
269
///////////////////////////////////////////////////////////////////////////////////////////////////
270

  
271
    void onPause()
272
      {
273
      if( mThread!=null ) mThread.setRunning(false);
274
      }
275

  
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277

  
278
    void onResume()
279
      {
280
      if( mThread!=null ) mThread.setRunning(true);
281
      }
282

  
283
///////////////////////////////////////////////////////////////////////////////////////////////////
284

  
285
    @Override
286
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
287
      {
288
      mWidth = width;
289
      mHeight= height;
290
      mMargin= height/10;
291

  
292
      mPointSize = (mWidth+mHeight)/80;
293
      mPaint.setTextSize((mWidth+mHeight)/60);
294
      mPaint.setTextAlign(Paint.Align.CENTER);
295

  
296
      final Rect textBounds = new Rect();
297
      String text = "1";
298
      mPaint.getTextBounds(text, 0, text.length(), textBounds);
299
      mFontHeight = textBounds.exactCenterY();
300

  
301
      refreshScreen = true;
302
      }
303

  
304
///////////////////////////////////////////////////////////////////////////////////////////////////
305

  
306
    @Override
307
    public void surfaceCreated(SurfaceHolder holder)
308
      {
309
      mThread = new GraphicsThread(getHolder(), this);
310
      mThread.setRunning(true);
311
      mThread.start();
312
      }
313

  
314
///////////////////////////////////////////////////////////////////////////////////////////////////
315

  
316
    @Override
317
    public void surfaceDestroyed(SurfaceHolder holder)
318
      {
319
      stopThread();
320
      }
321
}
322

  
src/main/java/org/distorted/examples/dynamic/DynamicSurfaceView.java
38 38
import org.distorted.library.type.Static2D;
39 39
import org.distorted.library.type.Static3D;
40 40

  
41
///////////////////////////////////////////////////////////////////
41
import java.lang.ref.WeakReference;
42

  
43
///////////////////////////////////////////////////////////////////////////////////////////////////
42 44

  
43 45
public class DynamicSurfaceView extends GLSurfaceView
44 46
    {
......
47 49
    public static final int DIM_3DXY = 2; 
48 50
    public static final int DIM_3DXZ = 3; 
49 51

  
50
    private static final int NUM_POINTS = 250;
52
    static final int NUM_POINTS = 250;
51 53
    private static final Object lock = new Object();
52 54

  
55
    private WeakReference<DynamicActivity> mAct;
56

  
53 57
    private static int halfScreenHeight=0;
54 58
    private static int halfScreenWidth =0;
55 59

  
......
81 85
    private float[] mPoints = new float[3*NUM_POINTS];
82 86
    private boolean mRunning;
83 87

  
84
///////////////////////////////////////////////////////////////////
88
///////////////////////////////////////////////////////////////////////////////////////////////////
85 89
    
86 90
    public DynamicSurfaceView(Context context, AttributeSet attrs)
87 91
      {
88 92
      super(context, attrs);
89
      
93

  
94
      DynamicActivity act = (DynamicActivity)context;
95
      mAct = new WeakReference<>(act);
96

  
90 97
      mPaint = new Paint();
91 98
      mPaint.setStyle(Style.FILL);
92 99
      mPaint.setAntiAlias(true);
......
104 111

  
105 112
      mRunning = false;
106 113

  
114
      clearPoints();
115

  
107 116
      di1D = new Dynamic1D(mDuration,mCount);
108 117
      p1N  = new Static1D(mNoise0);
109 118
      di2D = new Dynamic2D(mDuration,mCount);
......
148 157
      clearPoints();
149 158
      }
150 159

  
151
///////////////////////////////////////////////////////////////////
160
///////////////////////////////////////////////////////////////////////////////////////////////////
152 161

  
153 162
    public static void setHalfWidth(int hw)
154 163
      {
155 164
      halfScreenWidth = hw;
156 165
      }
157 166

  
158
///////////////////////////////////////////////////////////////////
167
///////////////////////////////////////////////////////////////////////////////////////////////////
159 168

  
160 169
    public static void setHalfHeight(int hh)
161 170
      {
162 171
      halfScreenHeight = hh;
163 172
      }
164 173

  
165
///////////////////////////////////////////////////////////////////
174
///////////////////////////////////////////////////////////////////////////////////////////////////
166 175

  
167 176
    public void setMode(int mode)
168 177
      {
......
171 180
      di3D.setMode(mode);
172 181
      }
173 182

  
174
///////////////////////////////////////////////////////////////////
183
///////////////////////////////////////////////////////////////////////////////////////////////////
175 184

  
176 185
    public void setDuration(int duration)
177 186
      {
......
182 191
      di3D.setDuration(duration);
183 192
      }
184 193

  
185
///////////////////////////////////////////////////////////////////
194
///////////////////////////////////////////////////////////////////////////////////////////////////
186 195

  
187 196
    public void setCount(float count)
188 197
      {
......
193 202
      di3D.setCount(count);
194 203
      }
195 204

  
196
///////////////////////////////////////////////////////////////////
205
///////////////////////////////////////////////////////////////////////////////////////////////////
197 206

  
198 207
    public void setNoise(float noise0, float noise1, float noise2)
199 208
      {
......
210 219
      di3D.setNoise(p3N);
211 220
      }
212 221
    
213
///////////////////////////////////////////////////////////////////
222
///////////////////////////////////////////////////////////////////////////////////////////////////
214 223

  
215 224
    public void setDimension(int dim)
216 225
      {
......
225 234
        }
226 235
      }
227 236
    
228
///////////////////////////////////////////////////////////////////
237
///////////////////////////////////////////////////////////////////////////////////////////////////
229 238
    
230 239
    public void drawCurve(Canvas c, long time)
231 240
      {
......
262 271
      mLastTime = time;
263 272
      }
264 273

  
265
///////////////////////////////////////////////////////////////////
274
///////////////////////////////////////////////////////////////////////////////////////////////////
266 275

  
267 276
    private void clearPoints()
268 277
      {
269 278
      for(int i=0; i<3*NUM_POINTS; i++)
270 279
         {
271
         mPoints[i] = -10.0f;
280
         mPoints[i] = -100000.0f;
272 281
         }
273 282
      }
274 283

  
275
///////////////////////////////////////////////////////////////////
284
///////////////////////////////////////////////////////////////////////////////////////////////////
276 285

  
277 286
    public void resetPoints()
278 287
      {
......
287 296
          case DIM_3DXY:
288 297
          case DIM_3DXZ: di3D.removeAll(); break;
289 298
          }
299

  
300
        mAct.get().setNumRedPoints(0);
290 301
        }
291 302
      }
292 303

  
293
///////////////////////////////////////////////////////////////////
304
///////////////////////////////////////////////////////////////////////////////////////////////////
294 305

  
295 306
    public void startDynamic()
296 307
      {
......
304 315
      di3D.resetToBeginning();
305 316
      }
306 317

  
307
///////////////////////////////////////////////////////////////////
318
///////////////////////////////////////////////////////////////////////////////////////////////////
308 319

  
309 320
    public void stopDynamic()
310 321
      {
311 322
      mRunning = false;
312 323
      }
313 324

  
314
///////////////////////////////////////////////////////////////////
325
///////////////////////////////////////////////////////////////////////////////////////////////////
315 326

  
316 327
    private void drawHorizontalAxis(Canvas c, String label)
317 328
      {
......
322 333
      }
323 334

  
324 335

  
325
///////////////////////////////////////////////////////////////////
336
///////////////////////////////////////////////////////////////////////////////////////////////////
326 337

  
327 338
    private void drawVerticalAxis(Canvas c, String label)
328 339
      {
......
332 343
      c.drawText(label, halfScreenWidth + mSizeT,                mSizeT , mPaint);
333 344
      }
334 345

  
335
///////////////////////////////////////////////////////////////////
346
///////////////////////////////////////////////////////////////////////////////////////////////////
336 347

  
337 348
    private void drawPath(Canvas c, Dynamic dyn, int index, long time)
338 349
      {
......
353 364
            {
354 365
            stopDynamic();
355 366
            }
367

  
368
          addNewSpeedPoint(time);
356 369
          }
357 370

  
358 371
        for(int i=0; i<NUM_POINTS; i++)
......
366 379
        }
367 380
      }
368 381

  
369
///////////////////////////////////////////////////////////////////
382
///////////////////////////////////////////////////////////////////////////////////////////////////
370 383

  
371 384
    private void drawRedPoints1D(Canvas c)
372 385
      {
......
379 392
        }
380 393
      }
381 394

  
382
///////////////////////////////////////////////////////////////////
395
///////////////////////////////////////////////////////////////////////////////////////////////////
383 396

  
384 397
    private void drawRedPoints2D(Canvas c)
385 398
      {
......
392 405
        }
393 406
      }
394 407

  
395
///////////////////////////////////////////////////////////////////
408
///////////////////////////////////////////////////////////////////////////////////////////////////
396 409

  
397 410
    private void drawRedPoints3D(Canvas c)
398 411
      {
......
405 418
        }
406 419
      }
407 420

  
408
///////////////////////////////////////////////////////////////////
421
///////////////////////////////////////////////////////////////////////////////////////////////////
409 422

  
410 423
    private void drawRedPoint(Canvas c, String label, float width, float height)
411 424
      {
......
415 428
      c.drawText(label, width,height-mFontHeight, mPaint);
416 429
      }
417 430

  
418
///////////////////////////////////////////////////////////////////
431
///////////////////////////////////////////////////////////////////////////////////////////////////
419 432

  
420 433
    private void addNewPoint(int x, int y)
421 434
      {
......
442 455
                       synchronized(lock)
443 456
                         {
444 457
                         di1D.add(new Static1D(x));
458
                         mAct.get().setNumRedPoints(len+1);
445 459
                         }
446 460
                       }
447 461
                     break;
......
464 478
                       synchronized(lock)
465 479
                         {
466 480
                         di2D.add(new Static2D(x,y));
481
                         mAct.get().setNumRedPoints(len+1);
467 482
                         }
468 483
                       }
469 484
                     break;
......
497 512
                     { 
498 513
                     synchronized(lock)
499 514
                       {
500
                       if( currentDim==DIM_3DXY )
501
                         {
502
                         di3D.add(new Static3D(x,y, halfScreenHeight));
503
                         }
504
                       if( currentDim==DIM_3DXZ )
505
                         {
506
                         di3D.add(new Static3D(x, halfScreenHeight,y));
507
                         }
515
                       if( currentDim==DIM_3DXY ) di3D.add(new Static3D(x,y, halfScreenHeight));
516
                       if( currentDim==DIM_3DXZ ) di3D.add(new Static3D(x, halfScreenHeight,y));
517
                       mAct.get().setNumRedPoints(len+1);
508 518
                       }
509 519
                     }
510 520
                   break; 
511 521
        }
512 522
      }
513 523
    
514
///////////////////////////////////////////////////////////////////
515
    
524
///////////////////////////////////////////////////////////////////////////////////////////////////
525

  
526
    private void addNewSpeedPoint(long time)
527
      {
528
      int prev = mPosition-1;
529
      if( prev<0 ) prev = NUM_POINTS-1;
530

  
531
      float xdiff = mPoints[3*prev  ]-mPoints[3*mPosition  ];
532
      float ydiff = mPoints[3*prev+1]-mPoints[3*mPosition+1];
533
      float zdiff = mPoints[3*prev+2]-mPoints[3*mPosition+2];
534

  
535
      float dist = (float)Math.sqrt( xdiff*xdiff + ydiff*ydiff + zdiff*zdiff );
536
      float speed= mDiffTime<=0 ? 0: dist / mDiffTime;
537
      float timepoint = ((float)(time-mStartTime))/mDuration;
538

  
539
      if( dist<1000.0f )   // otherwise this is a very first call; do not send it!
540
        {
541
        mAct.get().addPoint( timepoint - (int)timepoint, speed );
542
        }
543
      }
544

  
545
///////////////////////////////////////////////////////////////////////////////////////////////////
546

  
516 547
    @Override
517 548
    public boolean onTouchEvent(MotionEvent event)
518 549
      {
......
551 582
            
552 583
      return true;
553 584
      }
554
 
555
///////////////////////////////////////////////////////////////////
556 585
  }
src/main/res/layout/dynamicslayout.xml
140 140
        android:id="@+id/dynamicSurfaceView"
141 141
        android:layout_width="fill_parent"
142 142
        android:layout_height="0dp"
143
        android:layout_weight="1" />
143
        android:layout_weight="0.8" />
144

  
145
    <org.distorted.examples.dynamic.DynamicSpeedSurfaceView
146
        android:id="@+id/dynamicSpeedSurfaceView"
147
        android:layout_width="fill_parent"
148
        android:layout_height="0dp"
149
        android:layout_weight="0.2" />
144 150

  
145 151
    <LinearLayout
146 152
        android:orientation="horizontal"

Also available in: Unified diff