Revision f9afbbf3
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/examples/effects2d/Effects2DActivity.java | ||
---|---|---|
26 | 26 |
import android.opengl.GLSurfaceView; |
27 | 27 |
import android.os.Bundle; |
28 | 28 |
import android.view.View; |
29 |
import android.widget.SeekBar.OnSeekBarChangeListener;
|
|
30 |
import android.widget.SeekBar;
|
|
31 |
import android.widget.TextView;
|
|
29 |
import android.widget.AdapterView;
|
|
30 |
import android.widget.ArrayAdapter;
|
|
31 |
import android.widget.Spinner;
|
|
32 | 32 |
|
33 | 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
34 | 34 |
|
35 |
public class Effects2DActivity extends Activity implements OnSeekBarChangeListener
|
|
35 |
public class Effects2DActivity extends Activity implements AdapterView.OnItemSelectedListener
|
|
36 | 36 |
{ |
37 |
private static final float D_MULT=200.0f; |
|
38 |
private static final float C_MULT= 0.1f; |
|
39 |
|
|
40 |
private long effectID; |
|
41 |
|
|
42 |
private SeekBar barD, barC, barI; |
|
43 |
private TextView textD, textC, textI; |
|
44 |
|
|
37 |
private Spinner mID, mName, mType; |
|
38 |
private ArrayAdapter<String> mAdapterID, mAdapterName, mAdapterType; |
|
39 |
|
|
45 | 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
46 | 41 |
|
47 | 42 |
@Override |
... | ... | |
49 | 44 |
{ |
50 | 45 |
super.onCreate(savedInstanceState); |
51 | 46 |
|
52 |
setContentView(R.layout.scratchpadlayout); |
|
53 |
|
|
54 |
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 |
|
|
61 |
textD = (TextView)findViewById(R.id.scratchpadTextDuration); |
|
62 |
textC = (TextView)findViewById(R.id.scratchpadTextCount); |
|
63 |
textI = (TextView)findViewById(R.id.scratchpadTextID); |
|
64 |
|
|
65 |
barD.setProgress(100); |
|
66 |
barC.setProgress(10); |
|
67 |
barI.setProgress(0); |
|
68 |
|
|
69 |
textD.setText("Dur: 20 s"); |
|
70 |
textC.setText("Cou: 1.0"); |
|
71 |
textI.setText("ID: 0"); |
|
47 |
setContentView(R.layout.effects2dlayout); |
|
48 |
|
|
49 |
mID = (Spinner)findViewById(R.id.effects2d_spinnerID ); |
|
50 |
mName = (Spinner)findViewById(R.id.effects2d_spinnerName); |
|
51 |
mType = (Spinner)findViewById(R.id.effects2d_spinnerType); |
|
52 |
|
|
53 |
mID.setOnItemSelectedListener(this); |
|
54 |
mName.setOnItemSelectedListener(this); |
|
55 |
mType.setOnItemSelectedListener(this); |
|
56 |
|
|
57 |
String[] itemsID = new String[] {"1", "2", "3"}; |
|
58 |
String[] itemsName = new String[] { getText(R.string.distort ).toString(), |
|
59 |
getText(R.string.sink ).toString(), |
|
60 |
getText(R.string.transparency).toString(), |
|
61 |
getText(R.string.macroblock ).toString(), |
|
62 |
getText(R.string.chroma ).toString()}; |
|
63 |
String[] itemsType = new String[] {"VERTEX", "FRAGMENT"}; |
|
64 |
|
|
65 |
mAdapterID = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsID); |
|
66 |
mAdapterID.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
67 |
mID.setAdapter(mAdapterID); |
|
68 |
|
|
69 |
mAdapterName = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsName); |
|
70 |
mAdapterName.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
71 |
mName.setAdapter(mAdapterName); |
|
72 |
|
|
73 |
mAdapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsType); |
|
74 |
mAdapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
75 |
mType.setAdapter(mAdapterType); |
|
72 | 76 |
} |
73 | 77 |
|
74 | 78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
140 | 144 |
|
141 | 145 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
142 | 146 |
|
143 |
public void Brightness(View v)
|
|
147 |
public void Chroma(View v)
|
|
144 | 148 |
{ |
145 | 149 |
Effects2DSurfaceView.setEffect(4); |
146 |
} |
|
147 |
|
|
148 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
149 |
|
|
150 |
public void Print(View v) |
|
151 |
{ |
|
152 |
Effects2DRenderer.mBackground.printEffect(effectID); |
|
153 | 150 |
} |
154 | 151 |
|
155 | 152 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
156 | 153 |
|
157 |
public void Abort(View v)
|
|
154 |
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
|
|
158 | 155 |
{ |
159 |
Effects2DRenderer.mBackground.abortEffect(effectID);
|
|
160 |
}
|
|
156 |
// An item was selected. You can retrieve the selected item using
|
|
157 |
// parent.getItemAtPosition(pos)
|
|
161 | 158 |
|
162 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
163 |
|
|
164 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
165 |
{ |
|
166 |
float v, t; |
|
167 |
int i; |
|
168 |
|
|
169 |
switch (bar.getId()) |
|
159 |
switch(parent.getId()) |
|
170 | 160 |
{ |
171 |
case R.id.scratchpadSeekDuration: v = progress*D_MULT; |
|
172 |
i = (int)(v/100); |
|
173 |
t = i/10.0f; |
|
174 |
Effects2DSurfaceView.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 |
Effects2DSurfaceView.setCount(v); |
|
181 |
textC.setText("Cou: "+t); |
|
182 |
break; |
|
183 |
case R.id.scratchpadSeekID : effectID = progress; |
|
184 |
textI.setText("ID: "+progress); |
|
185 |
break; |
|
161 |
case R.id.effects2d_spinnerID : android.util.Log.d("EFFECTS2D", "ID spinner!!" ); break; |
|
162 |
case R.id.effects2d_spinnerName: android.util.Log.d("EFFECTS2D", "Name spinner!!"); break; |
|
163 |
case R.id.effects2d_spinnerType: android.util.Log.d("EFFECTS2D", "Type spinner!!"); break; |
|
186 | 164 |
} |
187 | 165 |
} |
188 | 166 |
|
189 | 167 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
190 | 168 |
|
191 |
public void onStartTrackingTouch(SeekBar bar) { } |
|
192 |
|
|
193 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
194 |
|
|
195 |
public void onStopTrackingTouch(SeekBar bar) { } |
|
169 |
public void onNothingSelected(AdapterView<?> parent) |
|
170 |
{ |
|
171 |
switch(parent.getId()) |
|
172 |
{ |
|
173 |
case R.id.effects2d_spinnerID : android.util.Log.d("EFFECTS2D", "(nothing) ID spinner!!" ); break; |
|
174 |
case R.id.effects2d_spinnerName: android.util.Log.d("EFFECTS2D", "(nothing) Name spinner!!"); break; |
|
175 |
case R.id.effects2d_spinnerType: android.util.Log.d("EFFECTS2D", "(nothing) Type spinner!!"); break; |
|
176 |
} |
|
177 |
} |
|
196 | 178 |
} |
Also available in: Unified diff
Upgrade what used to be the 'Scratchpad' app; step 2: reorganize layout