Revision 75c7def3
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/examples/fragment3d/Fragment3DActivity.java | ||
---|---|---|
44 | 44 |
import org.distorted.library.EffectTypes; |
45 | 45 |
import org.distorted.library.type.Dynamic1D; |
46 | 46 |
import org.distorted.library.type.Dynamic3D; |
47 |
import org.distorted.library.type.Dynamic4D; |
|
47 | 48 |
|
48 | 49 |
import java.util.ArrayList; |
49 | 50 |
|
50 | 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
51 | 52 |
|
52 | 53 |
public class Fragment3DActivity extends Activity |
53 |
implements OnSeekBarChangeListener, |
|
54 |
View.OnClickListener, |
|
54 |
implements View.OnClickListener, |
|
55 | 55 |
AdapterView.OnItemSelectedListener |
56 | 56 |
{ |
57 | 57 |
private static final int COLOR_OFF = 0xffffe81f; |
... | ... | |
70 | 70 |
private int mObjectType; |
71 | 71 |
private int mBitmap; |
72 | 72 |
|
73 |
// fields needed for the second 'apply fragment effects' screen |
|
74 |
// |
|
75 |
private TextView textCenter; |
|
76 |
private int centerX, centerY; |
|
77 |
private float fcenterX, fcenterY; |
|
78 | 73 |
private ArrayList<Fragment3DEffect> mEffects; |
79 | 74 |
|
80 | 75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
282 | 277 |
final View view = getLayoutInflater().inflate(R.layout.fragment3dlayout, null); |
283 | 278 |
|
284 | 279 |
setContentView(view); |
285 |
|
|
286 |
centerX = 50; |
|
287 |
centerY = 50; |
|
288 |
|
|
289 |
textCenter = (TextView)view.findViewById(R.id.fragment3dcenterText); |
|
290 |
computeCenter(); |
|
291 |
setCenterText(); |
|
292 |
|
|
293 |
SeekBar bar; |
|
294 |
|
|
295 |
bar = (SeekBar)view.findViewById(R.id.fragment3dcenterX); |
|
296 |
bar.setOnSeekBarChangeListener(this); |
|
297 |
bar.setProgress(centerX); |
|
298 |
|
|
299 |
bar = (SeekBar)view.findViewById(R.id.fragment3dcenterY); |
|
300 |
bar.setOnSeekBarChangeListener(this); |
|
301 |
bar.setProgress(centerY); |
|
302 | 280 |
} |
303 | 281 |
|
304 | 282 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
308 | 286 |
Fragment3DEffect chroma = new Fragment3DEffect(EffectNames.CHROMA); |
309 | 287 |
mEffects.add(chroma); |
310 | 288 |
|
311 |
View view = chroma.createView(this); |
|
312 | 289 |
LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout); |
290 |
View view = chroma.createView(this); |
|
313 | 291 |
layout.addView(view); |
292 |
View region = chroma.createRegion(this); |
|
293 |
layout.addView(region); |
|
314 | 294 |
|
315 | 295 |
Dynamic1D dyn1 = chroma.getDyn1(); |
316 | 296 |
Dynamic3D dyn3 = chroma.getDyn3(); |
297 |
Dynamic4D regi = chroma.getRegion(); |
|
317 | 298 |
|
318 |
mObject.chroma(dyn1,dyn3);
|
|
299 |
mObject.chroma(dyn1, dyn3, regi, false);
|
|
319 | 300 |
} |
320 | 301 |
|
321 | 302 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
325 | 306 |
Fragment3DEffect alpha = new Fragment3DEffect(EffectNames.ALPHA); |
326 | 307 |
mEffects.add(alpha); |
327 | 308 |
|
328 |
View view = alpha.createView(this); |
|
329 | 309 |
LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout); |
310 |
View view = alpha.createView(this); |
|
330 | 311 |
layout.addView(view); |
312 |
View region = alpha.createRegion(this); |
|
313 |
layout.addView(region); |
|
331 | 314 |
|
332 | 315 |
Dynamic1D dyn1 = alpha.getDyn1(); |
316 |
Dynamic4D regi = alpha.getRegion(); |
|
333 | 317 |
|
334 |
mObject.alpha(dyn1); |
|
318 |
mObject.alpha(dyn1, regi, false);
|
|
335 | 319 |
} |
336 | 320 |
|
337 | 321 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
341 | 325 |
Fragment3DEffect brightness = new Fragment3DEffect(EffectNames.BRIGHTNESS); |
342 | 326 |
mEffects.add(brightness); |
343 | 327 |
|
344 |
View view = brightness.createView(this); |
|
345 | 328 |
LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout); |
329 |
View view = brightness.createView(this); |
|
346 | 330 |
layout.addView(view); |
331 |
View region = brightness.createRegion(this); |
|
332 |
layout.addView(region); |
|
347 | 333 |
|
348 | 334 |
Dynamic1D dyn1 = brightness.getDyn1(); |
335 |
Dynamic4D regi = brightness.getRegion(); |
|
349 | 336 |
|
350 |
mObject.brightness(dyn1); |
|
337 |
mObject.brightness(dyn1, regi, false);
|
|
351 | 338 |
} |
352 | 339 |
|
353 | 340 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
357 | 344 |
Fragment3DEffect saturation = new Fragment3DEffect(EffectNames.SATURATION); |
358 | 345 |
mEffects.add(saturation); |
359 | 346 |
|
360 |
View view = saturation.createView(this); |
|
361 | 347 |
LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout); |
348 |
View view = saturation.createView(this); |
|
362 | 349 |
layout.addView(view); |
350 |
View region = saturation.createRegion(this); |
|
351 |
layout.addView(region); |
|
363 | 352 |
|
364 | 353 |
Dynamic1D dyn1 = saturation.getDyn1(); |
354 |
Dynamic4D regi = saturation.getRegion(); |
|
365 | 355 |
|
366 |
mObject.saturation(dyn1); |
|
356 |
mObject.saturation(dyn1, regi, false);
|
|
367 | 357 |
} |
368 | 358 |
|
369 | 359 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
376 | 366 |
mObject.abortEffects(EffectTypes.FRAGMENT); |
377 | 367 |
} |
378 | 368 |
|
379 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
380 |
|
|
381 |
private void computeCenter() |
|
382 |
{ |
|
383 |
Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView); |
|
384 |
|
|
385 |
fcenterX = centerX; |
|
386 |
fcenterY = centerY; |
|
387 |
|
|
388 |
view.getRenderer().setCenter( fcenterX, fcenterY ); |
|
389 |
} |
|
390 |
|
|
391 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
392 |
|
|
393 |
private void setCenterText() |
|
394 |
{ |
|
395 |
fcenterX = ((int)(100*fcenterX))/100.0f; |
|
396 |
fcenterY = ((int)(100*fcenterY))/100.0f; |
|
397 |
|
|
398 |
textCenter.setText("center("+fcenterX+","+fcenterY+")"); |
|
399 |
} |
|
400 |
|
|
401 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
402 |
|
|
403 |
public float getCenterX() |
|
404 |
{ |
|
405 |
return fcenterX; |
|
406 |
} |
|
407 |
|
|
408 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
409 |
|
|
410 |
public float getCenterY() |
|
411 |
{ |
|
412 |
return fcenterY; |
|
413 |
} |
|
414 |
|
|
415 | 369 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
416 | 370 |
// Overrides |
417 | 371 |
|
... | ... | |
455 | 409 |
Distorted.onDestroy(); |
456 | 410 |
super.onDestroy(); |
457 | 411 |
} |
458 |
|
|
459 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
460 |
|
|
461 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
462 |
{ |
|
463 |
switch (bar.getId()) |
|
464 |
{ |
|
465 |
case R.id.fragment3dcenterX: centerX = progress; computeCenter() ; setCenterText() ; break; |
|
466 |
case R.id.fragment3dcenterY: centerY = progress; computeCenter() ; setCenterText() ; break; |
|
467 |
} |
|
468 |
} |
|
469 |
|
|
470 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
471 |
|
|
472 |
public void onStartTrackingTouch(SeekBar bar) { } |
|
473 |
|
|
474 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
475 | 412 |
|
476 |
public void onStopTrackingTouch(SeekBar bar) { } |
|
477 | 413 |
} |
Also available in: Unified diff
Fragment3D close to done now!