Project

General

Profile

Download (9.17 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / dynamic / DynamicActivity.java @ b5636dbf

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 org.distorted.library.Distorted;
23
import org.distorted.library.type.Dynamic1D;
24
import org.distorted.examples.R;
25

    
26
import android.app.Activity;
27
import android.opengl.GLSurfaceView;
28
import android.os.Bundle;
29
import android.view.View;
30
import android.widget.SeekBar;
31
import android.widget.TextView;
32
import android.widget.SeekBar.OnSeekBarChangeListener;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
public class DynamicActivity extends Activity implements OnSeekBarChangeListener
37
    {
38
    private TextView textD, textN;
39
    private int p0,p1,p2;
40
    private int mDim, mMode;
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43
    @Override
44
    protected void onCreate(Bundle savedState)
45
      {
46
      super.onCreate(savedState);
47
      setContentView(R.layout.dynamicslayout);
48

    
49
      textD = (TextView)findViewById(R.id.dynamicTextDuration);
50
      textN = (TextView)findViewById(R.id.dynamicTextNoise);
51

    
52
      p0=p1=p2=0;
53
      mDim = DynamicSurfaceView.DIM_2D;
54
      mMode= Dynamic1D.MODE_LOOP;
55

    
56
      SeekBar barD = (SeekBar)findViewById(R.id.dynamicSeekDuration);
57
      barD.setOnSeekBarChangeListener(this);
58
      SeekBar bar0 = (SeekBar)findViewById(R.id.dynamicSeekNoise0);
59
      bar0.setOnSeekBarChangeListener(this);
60
      SeekBar bar1 = (SeekBar)findViewById(R.id.dynamicSeekNoise1);
61
      bar1.setOnSeekBarChangeListener(this);
62
      SeekBar bar2 = (SeekBar)findViewById(R.id.dynamicSeekNoise2);
63
      bar2.setOnSeekBarChangeListener(this);
64

    
65
      if( savedState==null )
66
        {
67
        barD.setProgress(50);
68
        bar0.setProgress(0);
69
        bar1.setProgress(0);
70
        bar2.setProgress(0);
71
        }
72
      }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75
    @Override
76
    protected void onResume() 
77
      {
78
      super.onResume();
79
      
80
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
81
      view.onResume();
82
      }
83

    
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85
    @Override
86
    protected void onPause() 
87
      {
88
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
89
      view.onPause();
90
         
91
      super.onPause();
92
      }
93
    
94
///////////////////////////////////////////////////////////////////////////////////////////////////
95
    @Override
96
    public void onStop()
97
      {
98
      super.onStop();
99
      }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102
    @Override
103
    public void onDestroy()
104
      {  
105
      Distorted.onDestroy();
106
      super.onDestroy();
107
      }     
108
 
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
    
111
    public void Loop(View v)
112
      {
113
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
114
      view.setMode(Dynamic1D.MODE_LOOP);
115
      mMode = Dynamic1D.MODE_LOOP;
116
      }     
117
    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

    
120
    public void Path(View v)
121
      {
122
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
123
      view.setMode(Dynamic1D.MODE_PATH);
124
      mMode = Dynamic1D.MODE_PATH;
125
      }  
126

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128

    
129
    public void Jump(View v)
130
      {
131
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
132
      view.setMode(Dynamic1D.MODE_JUMP);
133
      mMode = Dynamic1D.MODE_JUMP;
134
      }  
135
    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
    public void Dim1D(View v)
139
      {
140
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
141
      view.setDimension(DynamicSurfaceView.DIM_1D);
142
      mDim = DynamicSurfaceView.DIM_1D;
143
      }  
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

    
147
    public void Dim2D(View v)
148
      {
149
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
150
      view.setDimension(DynamicSurfaceView.DIM_2D);
151
      mDim = DynamicSurfaceView.DIM_2D;
152
      }  
153
    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

    
156
    public void Dim3DXY(View v)
157
      {
158
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
159
      view.setDimension(DynamicSurfaceView.DIM_3DXY);
160
      mDim = DynamicSurfaceView.DIM_3DXY;
161
      }  
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

    
165
    public void Dim3DXZ(View v)
166
      {
167
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
168
      view.setDimension(DynamicSurfaceView.DIM_3DXZ);
169
      mDim = DynamicSurfaceView.DIM_3DXZ;
170
      }  
171

    
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173

    
174
    @Override
175
    public void onSaveInstanceState(Bundle savedInstanceState)
176
      {
177
      super.onSaveInstanceState(savedInstanceState);
178

    
179
      savedInstanceState.putInt("dim" , mDim );
180
      savedInstanceState.putInt("mode", mMode);
181
      }
182

    
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

    
185
    @Override
186
    public void onRestoreInstanceState(Bundle savedInstanceState)
187
      {
188
      super.onRestoreInstanceState(savedInstanceState);
189

    
190
      mDim = savedInstanceState.getInt("dim");
191
      mMode= savedInstanceState.getInt("mode");
192

    
193
      switch(mDim)
194
        {
195
        case DynamicSurfaceView.DIM_1D  : Dim1D(null)  ; break;
196
        case DynamicSurfaceView.DIM_2D  : Dim2D(null)  ; break;
197
        case DynamicSurfaceView.DIM_3DXY: Dim3DXY(null); break;
198
        case DynamicSurfaceView.DIM_3DXZ: Dim3DXZ(null); break;
199
        }
200

    
201
      switch(mMode)
202
        {
203
        case Dynamic1D.MODE_JUMP: Jump(null); break;
204
        case Dynamic1D.MODE_PATH: Path(null); break;
205
        case Dynamic1D.MODE_LOOP: Loop(null); break;
206
        }
207
      }
208

    
209
///////////////////////////////////////////////////////////////////
210
    
211
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) 
212
      {
213
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
214
      int id = bar.getId();
215

    
216
      if( id == R.id.dynamicSeekDuration )
217
        {
218
        float v = progress*200;
219
        int i = (int)(v/100);
220
        float t = i/10.0f;
221
        view.setDuration((int)v);
222
        textD.setText("Duration: "+(int)t+" s");
223
        }
224
      else
225
        {
226
        switch(id)
227
          {
228
          case R.id.dynamicSeekNoise0  : p0 = progress; break;
229
          case R.id.dynamicSeekNoise1  : p1 = progress; break;
230
          case R.id.dynamicSeekNoise2  : p2 = progress; break;
231
          }
232

    
233
        view.setNoise(p0/100.0f,p1/100.0f,p2/100.0f);
234
        textN.setText("Noise: "+(p0/100.f)+" "+(p1/100.f)+" "+(p2/100.f));
235
        }
236
      }
237

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

    
240
    public void onStartTrackingTouch(SeekBar bar) { }
241
    
242
///////////////////////////////////////////////////////////////////
243

    
244
    public void onStopTrackingTouch(SeekBar bar)  { }
245
    
246
///////////////////////////////////////////////////////////////////
247
// end of file
248
}
(1-1/3)