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.effects2d;
|
21
|
|
22
|
import org.distorted.library.Distorted;
|
23
|
import org.distorted.examples.R;
|
24
|
import org.distorted.library.EffectNames;
|
25
|
import org.distorted.library.EffectTypes;
|
26
|
|
27
|
import android.app.Activity;
|
28
|
import android.opengl.GLSurfaceView;
|
29
|
import android.os.Bundle;
|
30
|
import android.view.View;
|
31
|
import android.widget.AdapterView;
|
32
|
import android.widget.ArrayAdapter;
|
33
|
import android.widget.Spinner;
|
34
|
import android.widget.TableLayout;
|
35
|
import android.widget.TableRow;
|
36
|
import android.widget.TextView;
|
37
|
import android.widget.Toast;
|
38
|
|
39
|
import java.util.ArrayList;
|
40
|
import java.util.HashMap;
|
41
|
|
42
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43
|
|
44
|
public class Effects2DActivity extends Activity implements AdapterView.OnItemSelectedListener
|
45
|
{
|
46
|
private Spinner mID, mName, mType;
|
47
|
private static ArrayAdapter<String> mAdapterName, mAdapterType;
|
48
|
private static ArrayAdapter<Long> mAdapterID;
|
49
|
|
50
|
private int mPosID, mPosName, mPosType;
|
51
|
private TableLayout mLayoutList;
|
52
|
|
53
|
private HashMap<Long,TableRow> mMap = new HashMap<>();
|
54
|
|
55
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56
|
|
57
|
@Override
|
58
|
protected void onCreate(Bundle savedInstanceState)
|
59
|
{
|
60
|
super.onCreate(savedInstanceState);
|
61
|
|
62
|
setContentView(R.layout.effects2dlayout);
|
63
|
|
64
|
mPosID = 0;
|
65
|
mPosName = 0;
|
66
|
mPosType = 0;
|
67
|
|
68
|
mID = (Spinner)findViewById(R.id.effects2d_spinnerID );
|
69
|
mName = (Spinner)findViewById(R.id.effects2d_spinnerName);
|
70
|
mType = (Spinner)findViewById(R.id.effects2d_spinnerType);
|
71
|
|
72
|
mID.setOnItemSelectedListener(this);
|
73
|
mName.setOnItemSelectedListener(this);
|
74
|
mType.setOnItemSelectedListener(this);
|
75
|
|
76
|
ArrayList<Long> itemsID = new ArrayList<>();
|
77
|
|
78
|
String[] itemsName = new String[] { getText(R.string.distort ).toString(),
|
79
|
getText(R.string.sink ).toString(),
|
80
|
getText(R.string.transparency).toString(),
|
81
|
getText(R.string.macroblock ).toString(),
|
82
|
getText(R.string.chroma ).toString()};
|
83
|
|
84
|
String[] itemsType = new String[] {"VERTEX", "FRAGMENT"};
|
85
|
|
86
|
mAdapterID = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsID);
|
87
|
mAdapterID.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
88
|
mID.setAdapter(mAdapterID);
|
89
|
|
90
|
mAdapterName = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsName);
|
91
|
mAdapterName.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
92
|
mName.setAdapter(mAdapterName);
|
93
|
|
94
|
mAdapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, itemsType);
|
95
|
mAdapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
96
|
mType.setAdapter(mAdapterType);
|
97
|
|
98
|
mLayoutList = (TableLayout)findViewById(R.id.effects2dTableList);
|
99
|
}
|
100
|
|
101
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
102
|
|
103
|
@Override
|
104
|
protected void onResume()
|
105
|
{
|
106
|
super.onResume();
|
107
|
|
108
|
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects2dSurfaceView);
|
109
|
mView.onResume();
|
110
|
}
|
111
|
|
112
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
113
|
|
114
|
@Override
|
115
|
protected void onPause()
|
116
|
{
|
117
|
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects2dSurfaceView);
|
118
|
mView.onPause();
|
119
|
|
120
|
super.onPause();
|
121
|
}
|
122
|
|
123
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
124
|
|
125
|
@Override
|
126
|
public void onStop()
|
127
|
{
|
128
|
super.onStop();
|
129
|
}
|
130
|
|
131
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
132
|
|
133
|
@Override
|
134
|
public void onDestroy()
|
135
|
{
|
136
|
Distorted.onDestroy();
|
137
|
super.onDestroy();
|
138
|
}
|
139
|
|
140
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
141
|
|
142
|
public void Distort(View v)
|
143
|
{
|
144
|
Effects2DSurfaceView.setEffect(0);
|
145
|
}
|
146
|
|
147
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
148
|
|
149
|
public void Sink(View v)
|
150
|
{
|
151
|
Effects2DSurfaceView.setEffect(1);
|
152
|
}
|
153
|
|
154
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
155
|
|
156
|
public void Transparency(View v)
|
157
|
{
|
158
|
Effects2DSurfaceView.setEffect(2);
|
159
|
}
|
160
|
|
161
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
162
|
|
163
|
public void Macroblock(View v)
|
164
|
{
|
165
|
Effects2DSurfaceView.setEffect(3);
|
166
|
}
|
167
|
|
168
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
169
|
|
170
|
public void Chroma(View v)
|
171
|
{
|
172
|
Effects2DSurfaceView.setEffect(4);
|
173
|
}
|
174
|
|
175
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
176
|
|
177
|
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
|
178
|
{
|
179
|
switch(parent.getId())
|
180
|
{
|
181
|
case R.id.effects2d_spinnerID : mPosID = pos; break;
|
182
|
case R.id.effects2d_spinnerName: mPosName = pos; break;
|
183
|
case R.id.effects2d_spinnerType: mPosType = pos; break;
|
184
|
}
|
185
|
}
|
186
|
|
187
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
188
|
|
189
|
public void onNothingSelected(AdapterView<?> parent)
|
190
|
{
|
191
|
}
|
192
|
|
193
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
194
|
|
195
|
public void removeByID(View view)
|
196
|
{
|
197
|
Long currID = (Long)mID.getItemAtPosition(mPosID);
|
198
|
|
199
|
Effects2DRenderer.mBackground.abortEffect(currID);
|
200
|
}
|
201
|
|
202
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
203
|
|
204
|
public void removeByName(View view)
|
205
|
{
|
206
|
EffectNames name;
|
207
|
|
208
|
switch(mPosName)
|
209
|
{
|
210
|
case 0: name = EffectNames.DISTORT ; break;
|
211
|
case 1: name = EffectNames.SINK ; break;
|
212
|
case 2: name = EffectNames.SMOOTH_ALPHA ; break;
|
213
|
case 3: name = EffectNames.MACROBLOCK ; break;
|
214
|
case 4: name = EffectNames.SMOOTH_CHROMA; break;
|
215
|
default: name = EffectNames.CONTRAST ;
|
216
|
}
|
217
|
|
218
|
Effects2DRenderer.mBackground.abortEffects(name);
|
219
|
}
|
220
|
|
221
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
222
|
|
223
|
public void removeByType(View view)
|
224
|
{
|
225
|
EffectTypes type;
|
226
|
|
227
|
switch(mPosType)
|
228
|
{
|
229
|
case 0: type = EffectTypes.VERTEX ; break;
|
230
|
case 1: type = EffectTypes.FRAGMENT; break;
|
231
|
default: type = EffectTypes.MATRIX;
|
232
|
}
|
233
|
|
234
|
Effects2DRenderer.mBackground.abortEffects(type);
|
235
|
}
|
236
|
|
237
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
238
|
|
239
|
public void effectAdded(final long id, final EffectNames name, final EffectTypes type)
|
240
|
{
|
241
|
if( id>=0 ) // we really added a new effect
|
242
|
{
|
243
|
mAdapterID.add(id);
|
244
|
mAdapterID.notifyDataSetChanged();
|
245
|
|
246
|
TableRow tr = new TableRow(this);
|
247
|
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
|
248
|
|
249
|
TextView b1 = new TextView(this);
|
250
|
b1.setText("ID: "+id);
|
251
|
b1.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
|
252
|
tr.addView(b1);
|
253
|
|
254
|
TextView b2 = new TextView(this);
|
255
|
b2.setText(name.name());
|
256
|
b2.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
|
257
|
tr.addView(b2);
|
258
|
|
259
|
TextView b3 = new TextView(this);
|
260
|
b3.setText(type.name());
|
261
|
b3.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
|
262
|
tr.addView(b3);
|
263
|
|
264
|
TextView b4 = new TextView(this);
|
265
|
b4.setText("LIVE");
|
266
|
b4.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
|
267
|
tr.addView(b4);
|
268
|
|
269
|
mMap.put(id,tr);
|
270
|
|
271
|
mLayoutList.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT));
|
272
|
}
|
273
|
else // id=-1, i.e. we failed to add new effect due to too many effects already
|
274
|
{
|
275
|
Toast.makeText(this, R.string.example_effects2d_toast , Toast.LENGTH_LONG).show();
|
276
|
}
|
277
|
}
|
278
|
|
279
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
280
|
|
281
|
public void effectRemoved(final long id)
|
282
|
{
|
283
|
runOnUiThread(new Runnable()
|
284
|
{
|
285
|
public void run()
|
286
|
{
|
287
|
mAdapterID.remove(id);
|
288
|
mAdapterID.notifyDataSetChanged();
|
289
|
|
290
|
TableRow row = mMap.remove(id);
|
291
|
|
292
|
if( row!=null )
|
293
|
{
|
294
|
mLayoutList.removeView(row);
|
295
|
}
|
296
|
else
|
297
|
{
|
298
|
android.util.Log.e("EFFECTS2D", "Impossible: id="+id+" not in the map!");
|
299
|
}
|
300
|
}
|
301
|
});
|
302
|
}
|
303
|
|
304
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
305
|
|
306
|
public void effectFinished(final long id)
|
307
|
{
|
308
|
runOnUiThread(new Runnable()
|
309
|
{
|
310
|
public void run()
|
311
|
{
|
312
|
TableRow row = mMap.get(id);
|
313
|
|
314
|
if( row!=null )
|
315
|
{
|
316
|
TextView v = (TextView)row.getVirtualChildAt(3);
|
317
|
v.setText("FINISHED");
|
318
|
}
|
319
|
}
|
320
|
});
|
321
|
}
|
322
|
}
|