Project

General

Profile

« Previous | Next » 

Revision 100e2da7

Added by Leszek Koltunski over 7 years ago

Progress with the 'Flag' test app.

View differences:

src/main/java/org/distorted/examples/flag/FlagActivity.java
20 20
package org.distorted.examples.flag;
21 21

  
22 22
import android.app.Activity;
23
import android.opengl.GLSurfaceView;
23 24
import android.os.Bundle;
25
import android.widget.SeekBar;
26
import android.widget.TextView;
24 27

  
28
import org.distorted.examples.R;
25 29
import org.distorted.library.Distorted;
30
import org.distorted.library.type.Static5D;
26 31

  
27 32
///////////////////////////////////////////////////////////////////////////////////////////////////
28 33

  
29
public class FlagActivity extends Activity
34
public class FlagActivity extends Activity implements SeekBar.OnSeekBarChangeListener
30 35
{
31
    private FlagSurfaceView mView;
36
    private SeekBar barAmplitude, barLength, barAngleA, barAngleB;
37
    private TextView textAmplitude, textLength, textAngleA, textAngleB;
38
    private SeekBar barNoiseAmplitude, barNoiseLength, barNoiseAngleA, barNoiseAngleB;
39
    private TextView textNoiseAmplitude, textNoiseLength, textNoiseAngleA, textNoiseAngleB;
32 40

  
41
    private Static5D noise;
42
    private String mStr;
33 43
///////////////////////////////////////////////////////////////////////////////////////////////////
34 44
    
35 45
    @Override
36 46
    protected void onCreate(Bundle savedState) 
37 47
      {
38 48
      super.onCreate(savedState);
39
      mView = new FlagSurfaceView(this);
40
      setContentView(mView);
49
      setContentView(R.layout.flaglayout);
50

  
51
      noise = new Static5D(0,0,0,0,0);
52
      mStr = new String();
53

  
54
      textAmplitude = (TextView)findViewById(R.id.flagAmplitude);
55
      textLength    = (TextView)findViewById(R.id.flagLength);
56
      textAngleA    = (TextView)findViewById(R.id.flagAngleA);
57
      textAngleB    = (TextView)findViewById(R.id.flagAngleB);
58

  
59
      barAmplitude  = (SeekBar)findViewById(R.id.flagSeekAmplitude);
60
      barLength     = (SeekBar)findViewById(R.id.flagSeekLength);
61
      barAngleA     = (SeekBar)findViewById(R.id.flagSeekAngleA);
62
      barAngleB     = (SeekBar)findViewById(R.id.flagSeekAngleB);
63

  
64
      barAmplitude.setOnSeekBarChangeListener(this);
65
      barLength.setOnSeekBarChangeListener(this);
66
      barAngleA.setOnSeekBarChangeListener(this);
67
      barAngleB.setOnSeekBarChangeListener(this);
68

  
69
      barAmplitude.setProgress(50);
70
      barLength.setProgress(50);
71
      barAngleA.setProgress(25);
72
      barAngleB.setProgress(1);
73

  
74
      textNoiseAmplitude = (TextView)findViewById(R.id.flagNoiseAmplitude);
75
      textNoiseLength    = (TextView)findViewById(R.id.flagNoiseLength);
76
      textNoiseAngleA    = (TextView)findViewById(R.id.flagNoiseAngleA);
77
      textNoiseAngleB    = (TextView)findViewById(R.id.flagNoiseAngleB);
78

  
79
      barNoiseAmplitude  = (SeekBar)findViewById(R.id.flagSeekNoiseAmplitude);
80
      barNoiseLength     = (SeekBar)findViewById(R.id.flagSeekNoiseLength);
81
      barNoiseAngleA     = (SeekBar)findViewById(R.id.flagSeekNoiseAngleA);
82
      barNoiseAngleB     = (SeekBar)findViewById(R.id.flagSeekNoiseAngleB);
83

  
84
      barNoiseAmplitude.setOnSeekBarChangeListener(this);
85
      barNoiseLength.setOnSeekBarChangeListener(this);
86
      barNoiseAngleA.setOnSeekBarChangeListener(this);
87
      barNoiseAngleB.setOnSeekBarChangeListener(this);
88

  
89
      barNoiseAmplitude.setProgress( (int)noise.getX() );
90
      barNoiseLength.setProgress   ( (int)noise.getY() );
91
      barNoiseAngleA.setProgress   ( (int)noise.getW() );
92
      barNoiseAngleB.setProgress   ( (int)noise.getV() );
93

  
94
      textNoiseAmplitude.setText("Noise 0.00");
95
      textNoiseLength.setText("Noise 0.00");
96
      textNoiseAngleA.setText("Noise 0.00");
97
      textNoiseAngleB.setText("Noise 0.00");
41 98
      }
42 99

  
43 100
///////////////////////////////////////////////////////////////////////////////////////////////////
......
45 102
    @Override
46 103
    protected void onPause() 
47 104
      {
105
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.flagSurfaceView);
48 106
      mView.onPause();
107

  
49 108
      super.onPause();
50 109
      }
51 110

  
......
55 114
    protected void onResume() 
56 115
      {
57 116
      super.onResume();
117

  
118
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.flagSurfaceView);
58 119
      mView.onResume();
59 120
      }
60 121
    
......
66 127
      Distorted.onDestroy();  
67 128
      super.onDestroy();
68 129
      }
130

  
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

  
133
    private void convert(int progress)
134
      {
135
           if( progress==  0 ) mStr="0.00";
136
      else if( progress==100 ) mStr="1.00";
137
      else if( progress< 10  ) mStr="0.0"+progress;
138
      else                     mStr="0."+progress;
139
      }
140

  
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142

  
143
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
144
      {
145
      switch (bar.getId())
146
        {
147
        case R.id.flagSeekAmplitude     : FlagRenderer.setAmplitude(progress);
148
                                          textAmplitude.setText("Amplitude "+progress);
149
                                          break;
150
        case R.id.flagSeekNoiseAmplitude: noise.set( (float)progress, noise.getY(), noise.getZ(), noise.getW(), noise.getV() );
151
                                          FlagRenderer.setNoise(noise);
152
                                          convert(progress);
153
                                          textNoiseAmplitude.setText("Noise "+mStr );
154
                                          break;
155
        case R.id.flagSeekLength        : FlagRenderer.setLength(progress);
156
                                          textLength.setText("Length "+(progress*2));
157
                                          break;
158
        case R.id.flagSeekNoiseLength   : noise.set( noise.getX(), (float)progress, noise.getZ(), noise.getW(), noise.getV() );
159
                                          FlagRenderer.setNoise(noise);
160
                                          convert(progress);
161
                                          textNoiseLength.setText("Noise "+mStr );
162
                                          break;
163
        case R.id.flagSeekAngleA        : FlagRenderer.setAngleA(progress);
164
                                          textAngleA.setText("Alpha "+((360*progress)/100));
165
                                          break;
166
        case R.id.flagSeekNoiseAngleA   : noise.set( noise.getX(), noise.getY(), noise.getZ() ,(float)progress, noise.getV() );
167
                                          FlagRenderer.setNoise(noise);
168
                                          convert(progress);
169
                                          textNoiseAngleA.setText("Noise "+mStr );
170
                                          break;
171
        case R.id.flagSeekAngleB        : FlagRenderer.setAngleB(progress);
172
                                          textAngleB.setText("Beta "+((360*progress)/100));
173
                                          break;
174
        case R.id.flagSeekNoiseAngleB   : noise.set( noise.getX(), noise.getY(), noise.getZ(), noise.getW(), (float)progress );
175
                                          FlagRenderer.setNoise(noise);
176
                                          convert(progress);
177
                                          textNoiseAngleB.setText("Noise "+mStr );
178
                                          break;
179
        }
180
      }
181

  
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

  
184
    public void onStartTrackingTouch(SeekBar bar) { }
185

  
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187

  
188
    public void onStopTrackingTouch(SeekBar bar)  { }
189

  
69 190
}

Also available in: Unified diff