Project

General

Profile

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

examples / src / main / java / org / distorted / examples / scratchpad / ScratchpadActivity.java @ bc0a685b

1 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 5068fa06 Leszek Koltunski
package org.distorted.examples.scratchpad;
21 427ab7bf Leszek Koltunski
22 5068fa06 Leszek Koltunski
import org.distorted.library.Distorted;
23
import org.distorted.examples.R;
24 427ab7bf Leszek Koltunski
25
import android.app.Activity;
26
import android.opengl.GLSurfaceView;
27
import android.os.Bundle;
28
import android.view.View;
29
import android.widget.SeekBar.OnSeekBarChangeListener;
30
import android.widget.SeekBar;
31
import android.widget.TextView;
32
33 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
34 427ab7bf Leszek Koltunski
35
public class ScratchpadActivity extends Activity implements OnSeekBarChangeListener
36 bc0a685b Leszek Koltunski
  {
37
  private static final float D_MULT=200.0f;
38
  private static final float C_MULT=  0.1f;
39 427ab7bf Leszek Koltunski
   
40 bc0a685b Leszek Koltunski
  private long effectID;
41 427ab7bf Leszek Koltunski
   
42 bc0a685b Leszek Koltunski
  private SeekBar barD, barC, barI;
43
  private TextView textD, textC, textI;
44 427ab7bf Leszek Koltunski
   
45 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
46
47
  @Override
48
  protected void onCreate(Bundle savedInstanceState) 
49
    {
50
    super.onCreate(savedInstanceState);
51 427ab7bf Leszek Koltunski
 
52 bc0a685b Leszek Koltunski
    setContentView(R.layout.scratchpadlayout);
53 427ab7bf Leszek Koltunski
      
54 bc0a685b Leszek Koltunski
    barD = (SeekBar)findViewById(R.id.scratchpadSeekDuration);
55
    barD.setOnSeekBarChangeListener(this); 
56
    barC = (SeekBar)findViewById(R.id.scratchpadSeekCount);
57
    barC.setOnSeekBarChangeListener(this); 
58
    barI = (SeekBar)findViewById(R.id.scratchpadSeekID);
59
    barI.setOnSeekBarChangeListener(this); 
60 427ab7bf Leszek Koltunski
        
61 bc0a685b Leszek Koltunski
    textD = (TextView)findViewById(R.id.scratchpadTextDuration);
62
    textC = (TextView)findViewById(R.id.scratchpadTextCount);
63
    textI = (TextView)findViewById(R.id.scratchpadTextID);
64 427ab7bf Leszek Koltunski
      
65 bc0a685b Leszek Koltunski
    barD.setProgress(100);
66
    barC.setProgress(10);
67
    barI.setProgress(0);
68 427ab7bf Leszek Koltunski
      
69 bc0a685b Leszek Koltunski
    textD.setText("Dur: 20 s");
70
    textC.setText("Cou: 1.0");
71
    textI.setText("ID: 0");
72
    }
73 427ab7bf Leszek Koltunski
74 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
75
76
  @Override
77
  protected void onResume() 
78
    {
79
    super.onResume();
80 427ab7bf Leszek Koltunski
      
81 bc0a685b Leszek Koltunski
    GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.scratchpadSurfaceView);
82
    mView.onResume();
83
    }
84 427ab7bf Leszek Koltunski
85 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
86
87
  @Override
88
  protected void onPause() 
89
    {
90
    GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.scratchpadSurfaceView);
91
    mView.onPause();
92 427ab7bf Leszek Koltunski
      
93 bc0a685b Leszek Koltunski
    super.onPause();
94
    }
95 427ab7bf Leszek Koltunski
    
96 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
97 427ab7bf Leszek Koltunski
98 bc0a685b Leszek Koltunski
  @Override
99
  public void onStop()
100
    {
101
    super.onStop();
102
    }
103
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105
106
  @Override
107
  public void onDestroy()
108
    {
109
    Distorted.onDestroy();
110
    super.onDestroy();
111
    }     
112 427ab7bf Leszek Koltunski
 
113 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
114 427ab7bf Leszek Koltunski
    
115 bc0a685b Leszek Koltunski
  public void Distort(View v)
116
    {
117
    ScratchpadSurfaceView.setEffect(0);
118
    }     
119 427ab7bf Leszek Koltunski
    
120 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
121 427ab7bf Leszek Koltunski
122 bc0a685b Leszek Koltunski
  public void Sink(View v)
123
    {
124
    ScratchpadSurfaceView.setEffect(1);
125
    }       
126 427ab7bf Leszek Koltunski
127 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
128 427ab7bf Leszek Koltunski
    
129 bc0a685b Leszek Koltunski
  public void Transparency(View v)
130
    {
131
    ScratchpadSurfaceView.setEffect(2);
132
    }     
133 427ab7bf Leszek Koltunski
    
134 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
135 427ab7bf Leszek Koltunski
136 bc0a685b Leszek Koltunski
  public void Macroblock(View v)
137
    {
138
    ScratchpadSurfaceView.setEffect(3);
139
    }       
140 427ab7bf Leszek Koltunski
 
141 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
142 427ab7bf Leszek Koltunski
143 bc0a685b Leszek Koltunski
  public void Brightness(View v)
144
    {
145
    ScratchpadSurfaceView.setEffect(4);
146
    }       
147 427ab7bf Leszek Koltunski
     
148 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
149 427ab7bf Leszek Koltunski
150 bc0a685b Leszek Koltunski
  public void Print(View v)
151
    {
152
    ScratchpadRenderer.mBackground.printEffect(effectID);
153
    }
154 427ab7bf Leszek Koltunski
155 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
156 427ab7bf Leszek Koltunski
157 bc0a685b Leszek Koltunski
  public void Abort(View v)
158
    {
159
    ScratchpadRenderer.mBackground.abortEffect(effectID);
160
    }
161 427ab7bf Leszek Koltunski
162 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
163 427ab7bf Leszek Koltunski
    
164 bc0a685b Leszek Koltunski
  public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) 
165
    {
166
    float v, t; 
167
    int i;
168 427ab7bf Leszek Koltunski
      
169 bc0a685b Leszek Koltunski
    switch (bar.getId()) 
170
      {
171
      case R.id.scratchpadSeekDuration: v = progress*D_MULT;
172
                                        i = (int)(v/100);
173
                                        t = i/10.0f;
174
                                        ScratchpadSurfaceView.setDuration((int)v);
175
                                        textD.setText("Dur: "+(int)t+" s");
176
                                        break;
177
      case R.id.scratchpadSeekCount   : v = progress*C_MULT;
178
                                        i = (int)(v*10);
179
                                        t = i/10.0f;
180
                                        ScratchpadSurfaceView.setCount(v);
181
                                        textC.setText("Cou: "+t);
182
                                        break;
183
      case R.id.scratchpadSeekID      : effectID = progress;
184
                                        textI.setText("ID: "+progress);
185
                                        break;                        
186 427ab7bf Leszek Koltunski
      }
187 bc0a685b Leszek Koltunski
    }
188 427ab7bf Leszek Koltunski
189 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
190 427ab7bf Leszek Koltunski
191 bc0a685b Leszek Koltunski
  public void onStartTrackingTouch(SeekBar bar) { }
192 427ab7bf Leszek Koltunski
    
193 bc0a685b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
194 427ab7bf Leszek Koltunski
195 bc0a685b Leszek Koltunski
  public void onStopTrackingTouch(SeekBar bar)  { }
196
  }