Project

General

Profile

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

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

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 progress0, progress1, progress2;
40

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

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

    
51
      SeekBar bar = (SeekBar)findViewById(R.id.dynamicSeekDuration);
52
      bar.setOnSeekBarChangeListener(this);
53
      bar.setProgress(50);
54

    
55
      progress0=0;
56
      progress1=0;
57
      progress2=0;
58

    
59
      bar = (SeekBar)findViewById(R.id.dynamicSeekNoise0);
60
      bar.setProgress(0);
61
      bar.setOnSeekBarChangeListener(this);
62
      bar = (SeekBar)findViewById(R.id.dynamicSeekNoise1);
63
      bar.setProgress(0);
64
      bar.setOnSeekBarChangeListener(this);
65
      bar = (SeekBar)findViewById(R.id.dynamicSeekNoise2);
66
      bar.setProgress(0);
67
      bar.setOnSeekBarChangeListener(this);
68
      }
69

    
70
///////////////////////////////////////////////////////////////////
71
    @Override
72
    protected void onResume() 
73
      {
74
      super.onResume();
75
      
76
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
77
      view.onResume();
78
      }
79

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

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

    
115
    public void Path(View v)
116
      {
117
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
118
      view.setMode(Dynamic1D.MODE_PATH);
119
      }  
120

    
121
///////////////////////////////////////////////////////////////////
122

    
123
    public void Jump(View v)
124
      {
125
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
126
      view.setMode(Dynamic1D.MODE_JUMP);
127
      }  
128
    
129
///////////////////////////////////////////////////////////////////
130

    
131
    public void Dim1D(View v)
132
      {
133
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
134
      view.setDimension(DynamicSurfaceView.DIM_1D);
135
      }  
136

    
137
///////////////////////////////////////////////////////////////////
138

    
139
    public void Dim2D(View v)
140
      {
141
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
142
      view.setDimension(DynamicSurfaceView.DIM_2D);
143
      }  
144
    
145
///////////////////////////////////////////////////////////////////
146

    
147
    public void Dim3DXY(View v)
148
      {
149
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
150
      view.setDimension(DynamicSurfaceView.DIM_3DXY);
151
      }  
152

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

    
155
    public void Dim3DXZ(View v)
156
      {
157
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
158
      view.setDimension(DynamicSurfaceView.DIM_3DXZ);
159
      }  
160
    
161
///////////////////////////////////////////////////////////////////
162
    
163
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) 
164
      {
165
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
166
      int id = bar.getId();
167

    
168
      if( id == R.id.dynamicSeekDuration )
169
        {
170
        float v = progress*200;
171
        int i = (int)(v/100);
172
        float t = i/10.0f;
173
        view.setDuration((int)v);
174
        textD.setText("Duration: "+(int)t+" s");
175
        }
176
      else
177
        {
178
        switch(id)
179
          {
180
          case R.id.dynamicSeekNoise0  : progress0 = progress; break;
181
          case R.id.dynamicSeekNoise1  : progress1 = progress; break;
182
          case R.id.dynamicSeekNoise2  : progress2 = progress; break;
183
          }
184

    
185
        view.setNoise(progress0/100.0f,progress1/100.0f,progress2/100.0f);
186
        textN.setText("Noise: "+(progress0/100.f)+" "+(progress1/100.f)+" "+(progress2/100.f));
187
        }
188
      }
189

    
190
///////////////////////////////////////////////////////////////////
191

    
192
    public void onStartTrackingTouch(SeekBar bar) { }
193
    
194
///////////////////////////////////////////////////////////////////
195

    
196
    public void onStopTrackingTouch(SeekBar bar)  { }
197
    
198
///////////////////////////////////////////////////////////////////
199
// end of file
200
}
(1-1/3)