Revision 8d5a8e06
Added by Leszek Koltunski about 5 years ago
src/main/java/org/distorted/examples/effectqueue/EffectQueueActivity.java | ||
---|---|---|
50 | 50 |
private int mPosID, mPosName, mPosType; |
51 | 51 |
private TableLayout mLayoutList; |
52 | 52 |
|
53 |
private HashMap<Long,TableRow> mMap = new HashMap<>(); |
|
53 |
private class EffectRow |
|
54 |
{ |
|
55 |
Effect effect; |
|
56 |
TableRow row; |
|
57 |
|
|
58 |
EffectRow(Effect e, TableRow tr) |
|
59 |
{ |
|
60 |
effect = e; |
|
61 |
row = tr; |
|
62 |
} |
|
63 |
} |
|
64 |
|
|
65 |
private ArrayList<EffectRow> mList = new ArrayList<>(); |
|
54 | 66 |
|
55 | 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
56 | 68 |
|
... | ... | |
173 | 185 |
Long currEffect = (Long)mID.getItemAtPosition(mPosID); |
174 | 186 |
EffectQueueSurfaceView v = findViewById(R.id.effects2dSurfaceView); |
175 | 187 |
v.getRenderer().getEffects().abortById(currEffect); |
188 |
|
|
189 |
int numRows = mList.size(); |
|
190 |
|
|
191 |
for(int i=0; i<numRows; i++) |
|
192 |
{ |
|
193 |
Effect effect = mList.get(i).effect; |
|
194 |
|
|
195 |
if( effect.getID() == currEffect ) |
|
196 |
{ |
|
197 |
effectRemoved(i); |
|
198 |
break; |
|
199 |
} |
|
200 |
} |
|
176 | 201 |
} |
177 | 202 |
catch(IndexOutOfBoundsException ex) |
178 | 203 |
{ |
... | ... | |
196 | 221 |
default: name = EffectName.CONTRAST ; |
197 | 222 |
} |
198 | 223 |
|
224 |
int numRows = mList.size(); |
|
225 |
|
|
226 |
for(int i=0; i<numRows; i++) |
|
227 |
{ |
|
228 |
Effect effect = mList.get(i).effect; |
|
229 |
|
|
230 |
if( effect.getName() == name ) |
|
231 |
{ |
|
232 |
effectRemoved(i); |
|
233 |
i--; |
|
234 |
numRows--; |
|
235 |
} |
|
236 |
} |
|
237 |
|
|
199 | 238 |
EffectQueueSurfaceView v = findViewById(R.id.effects2dSurfaceView); |
200 | 239 |
v.getRenderer().getEffects().abortByName(name); |
201 | 240 |
} |
... | ... | |
213 | 252 |
default: type = EffectType.MATRIX; |
214 | 253 |
} |
215 | 254 |
|
255 |
int numRows = mList.size(); |
|
256 |
|
|
257 |
for(int i=0; i<numRows; i++) |
|
258 |
{ |
|
259 |
Effect effect = mList.get(i).effect; |
|
260 |
|
|
261 |
if( effect.getType() == type ) |
|
262 |
{ |
|
263 |
effectRemoved(i); |
|
264 |
i--; |
|
265 |
numRows--; |
|
266 |
} |
|
267 |
} |
|
268 |
|
|
216 | 269 |
EffectQueueSurfaceView v = findViewById(R.id.effects2dSurfaceView); |
217 | 270 |
v.getRenderer().getEffects().abortByType(type); |
218 | 271 |
} |
... | ... | |
223 | 276 |
{ |
224 | 277 |
if( success ) // we really added a new effect |
225 | 278 |
{ |
279 |
EffectQueueSurfaceView v = findViewById(R.id.effects2dSurfaceView); |
|
280 |
effect.notifyWhenFinished(v.getRenderer()); |
|
281 |
|
|
226 | 282 |
mAdapterID.add(effect.getID()); |
227 | 283 |
mAdapterID.notifyDataSetChanged(); |
228 | 284 |
|
... | ... | |
249 | 305 |
b4.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); |
250 | 306 |
tr.addView(b4); |
251 | 307 |
|
252 |
mMap.put(effect.getID(),tr);
|
|
308 |
mList.add(new EffectRow(effect,tr));
|
|
253 | 309 |
|
254 | 310 |
mLayoutList.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT)); |
255 | 311 |
} |
... | ... | |
261 | 317 |
|
262 | 318 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
263 | 319 |
|
264 |
public void effectRemoved(final long id)
|
|
320 |
private void effectRemoved(int index)
|
|
265 | 321 |
{ |
266 |
runOnUiThread(new Runnable() |
|
267 |
{ |
|
268 |
public void run() |
|
269 |
{ |
|
270 |
mAdapterID.remove(id); |
|
271 |
mAdapterID.notifyDataSetChanged(); |
|
322 |
EffectRow er = mList.remove(index); |
|
272 | 323 |
|
273 |
TableRow row = mMap.remove(id); |
|
324 |
mAdapterID.remove(er.effect.getID()); |
|
325 |
mAdapterID.notifyDataSetChanged(); |
|
274 | 326 |
|
275 |
if( row!=null ) |
|
276 |
{ |
|
277 |
mLayoutList.removeView(row); |
|
278 |
} |
|
279 |
else |
|
280 |
{ |
|
281 |
android.util.Log.e("EFFECTS2D", "Impossible: id="+id+" not in the map!"); |
|
282 |
} |
|
283 |
} |
|
284 |
}); |
|
327 |
if( er.row!=null ) |
|
328 |
{ |
|
329 |
mLayoutList.removeView(er.row); |
|
330 |
} |
|
331 |
else |
|
332 |
{ |
|
333 |
android.util.Log.e("EFFECTQUEUE", "Impossible: id="+er.effect.getID()+" not in the map!"); |
|
334 |
} |
|
285 | 335 |
} |
286 | 336 |
|
287 | 337 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
292 | 342 |
{ |
293 | 343 |
public void run() |
294 | 344 |
{ |
295 |
TableRow row = mMap.get(id); |
|
345 |
TableRow row = null; |
|
346 |
|
|
347 |
int numRows = mList.size(); |
|
348 |
|
|
349 |
for(int i=0; i<numRows; i++) |
|
350 |
{ |
|
351 |
EffectRow er = mList.get(i); |
|
352 |
|
|
353 |
if( er.effect.getID() == id ) |
|
354 |
{ |
|
355 |
row = er.row; |
|
356 |
break; |
|
357 |
} |
|
358 |
} |
|
296 | 359 |
|
297 | 360 |
if( row!=null ) |
298 | 361 |
{ |
Also available in: Unified diff
Simplify the way applications can get notifications when an effect finishes.
Now, instead of the 'DistortedEffects.(de)registerForNotifications()' 2 APIs, we call a single 'Effect.notifyWhenFinished()'.