Revision edafb4a7
Added by Leszek Koltunski almost 8 years ago
src/main/java/org/distorted/examples/fragment3d/Fragment3DActivity.java | ||
---|---|---|
42 | 42 |
import org.distorted.library.DistortedObject; |
43 | 43 |
import org.distorted.library.EffectNames; |
44 | 44 |
|
45 |
import java.util.ArrayList; |
|
46 |
|
|
45 | 47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
46 | 48 |
|
47 | 49 |
public class Fragment3DActivity extends Activity |
48 |
implements OnSeekBarChangeListener, |
|
49 |
View.OnClickListener, |
|
50 |
implements View.OnClickListener, |
|
50 | 51 |
AdapterView.OnItemSelectedListener |
51 | 52 |
{ |
52 | 53 |
private static final int COLOR_OFF = 0xffffe81f; |
... | ... | |
54 | 55 |
|
55 | 56 |
private boolean firstScreen; |
56 | 57 |
|
57 |
// fields needed for the first 'pick-a-shape' screen |
|
58 |
// |
|
59 | 58 |
private int mNumCols = 3; |
60 | 59 |
private int mNumRows = 3; |
61 | 60 |
private NumberPicker mColsPicker, mRowsPicker; |
... | ... | |
65 | 64 |
private int mObjectType; |
66 | 65 |
private int mBitmap; |
67 | 66 |
|
68 |
// fields needed for the second 'apply fragment effects' screen |
|
69 |
// |
|
70 |
private SeekBar bar; |
|
71 |
private TextView textChroma, textAlpha, textBrightness, textSaturation, textCenter; |
|
72 |
private int chromaL, chromaR, chromaG, chromaB; |
|
73 |
private int alphaL; |
|
74 |
private int brightnessL; |
|
75 |
private int saturationL; |
|
76 |
private int centerX, centerY; |
|
77 |
|
|
78 |
private float fchromaL, fchromaR, fchromaG, fchromaB; |
|
79 |
private float falphaL; |
|
80 |
private float fbrightnessL; |
|
81 |
private float fsaturationL; |
|
82 |
private float fcenterX, fcenterY; |
|
83 |
private EffectNames[] effects = new EffectNames[4]; |
|
67 |
private ArrayList<Fragment3DEffect> mEffects = new ArrayList<>(); |
|
68 |
private DistortedBitmap mCenter = null; |
|
84 | 69 |
|
85 | 70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
86 | 71 |
|
... | ... | |
219 | 204 |
firstScreen = false; |
220 | 205 |
mObject = new DistortedBitmap(100,100,mNumCols); |
221 | 206 |
setContentView(R.layout.fragment3dlayout); |
222 |
Default(null); |
|
223 | 207 |
} |
224 | 208 |
else |
225 | 209 |
{ |
... | ... | |
248 | 232 |
str += mShape[i] ? "1" : "0"; |
249 | 233 |
|
250 | 234 |
mObject = new DistortedCubes(mNumCols, str, 10); |
251 |
|
|
252 | 235 |
setContentView(R.layout.fragment3dlayout); |
253 |
Default(null); |
|
254 | 236 |
} |
255 | 237 |
|
256 | 238 |
|
... | ... | |
281 | 263 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
282 | 264 |
// 'second screen' methods |
283 | 265 |
|
284 |
public void Default(View view) |
|
285 |
{ |
|
286 |
effects[0] = EffectNames.CHROMA; |
|
287 |
effects[1] = EffectNames.ALPHA; |
|
288 |
effects[2] = EffectNames.BRIGHTNESS; |
|
289 |
effects[3] = EffectNames.SATURATION; |
|
290 |
|
|
291 |
chromaL = 0; |
|
292 |
chromaR = 0; |
|
293 |
chromaG = 0; |
|
294 |
chromaB = 0; |
|
295 |
|
|
296 |
alphaL = 0; |
|
297 |
brightnessL= 0; |
|
298 |
saturationL= 0; |
|
299 |
|
|
300 |
centerX = 50; |
|
301 |
centerY = 50; |
|
302 |
|
|
303 |
textCenter = (TextView)findViewById(R.id.fragment3dcenterText); |
|
304 |
computeCenter(); |
|
305 |
setCenterText(); |
|
306 |
|
|
307 |
setBar(R.id.fragment3dcenterX, centerX); |
|
308 |
setBar(R.id.fragment3dcenterY, centerY); |
|
309 |
|
|
310 |
addViews(); |
|
311 |
} |
|
312 |
|
|
313 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
314 |
|
|
315 |
private void addViews() |
|
266 |
private void removeAllViews() |
|
316 | 267 |
{ |
317 | 268 |
LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout); |
318 |
|
|
319 |
layout.removeAllViews(); |
|
320 |
|
|
321 |
View chroma = getLayoutInflater().inflate(R.layout.fragment3dchroma , null); |
|
322 |
View alpha = getLayoutInflater().inflate(R.layout.fragment3dalpha , null); |
|
323 |
View brightness= getLayoutInflater().inflate(R.layout.fragment3dbrightness, null); |
|
324 |
View saturation= getLayoutInflater().inflate(R.layout.fragment3dsaturation, null); |
|
325 |
|
|
326 |
for( int i=effects.length-1 ; i>=0 ; i-- ) |
|
327 |
{ |
|
328 |
switch(effects[i]) |
|
329 |
{ |
|
330 |
case CHROMA : layout.addView(chroma , 0); break; |
|
331 |
case ALPHA : layout.addView(alpha , 0); break; |
|
332 |
case BRIGHTNESS : layout.addView(brightness, 0); break; |
|
333 |
case SATURATION : layout.addView(saturation, 0); break; |
|
334 |
} |
|
335 |
} |
|
336 |
|
|
337 |
textChroma = (TextView)findViewById(R.id.fragment3dchromaText); |
|
338 |
textAlpha = (TextView)findViewById(R.id.fragment3dalphaText); |
|
339 |
textBrightness= (TextView)findViewById(R.id.fragment3dbrightnessText); |
|
340 |
textSaturation= (TextView)findViewById(R.id.fragment3dsaturationText); |
|
341 |
|
|
342 |
setChromaText(); |
|
343 |
setAlphaText(); |
|
344 |
setBrightnessText(); |
|
345 |
setSaturationText(); |
|
346 |
|
|
347 |
setBar(R.id.fragment3dchromaBar1, chromaL); |
|
348 |
setBar(R.id.fragment3dchromaBar2, chromaR); |
|
349 |
setBar(R.id.fragment3dchromaBar3, chromaG); |
|
350 |
setBar(R.id.fragment3dchromaBar4, chromaB); |
|
351 |
|
|
352 |
setBar(R.id.fragment3dalphaBar1 , alphaL); |
|
353 |
setBar(R.id.fragment3dbrightnessBar1, brightnessL); |
|
354 |
setBar(R.id.fragment3dsaturationBar1, saturationL); |
|
355 |
|
|
356 |
Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView); |
|
357 |
view.getRenderer().setOrder(effects); |
|
358 |
} |
|
359 |
|
|
360 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
361 |
|
|
362 |
private void moveUp(EffectNames name) |
|
363 |
{ |
|
364 |
int len = effects.length-1; |
|
365 |
int index = -1; |
|
366 |
|
|
367 |
for(int i=0; i<=len; i++) |
|
368 |
{ |
|
369 |
if( effects[i]==name ) |
|
370 |
{ |
|
371 |
index=i; |
|
372 |
break; |
|
373 |
} |
|
374 |
} |
|
375 |
|
|
376 |
if( index==0 ) |
|
377 |
{ |
|
378 |
for(int i=0; i<len; i++) |
|
379 |
effects[i] = effects[i+1]; |
|
380 |
|
|
381 |
effects[len] = name; |
|
382 |
} |
|
383 |
else if( index>0 ) |
|
384 |
{ |
|
385 |
effects[index] = effects[index-1]; |
|
386 |
effects[index-1] = name; |
|
387 |
} |
|
388 |
|
|
389 |
addViews(); |
|
390 |
} |
|
391 |
|
|
392 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
393 |
|
|
394 |
public void ButtonChroma(View v) |
|
395 |
{ |
|
396 |
moveUp(EffectNames.CHROMA); |
|
397 |
} |
|
398 |
|
|
399 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
400 |
|
|
401 |
public void ButtonAlpha(View v) |
|
402 |
{ |
|
403 |
moveUp(EffectNames.ALPHA); |
|
404 |
} |
|
405 |
|
|
406 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
407 |
|
|
408 |
public void ButtonBrightness(View v) |
|
409 |
{ |
|
410 |
moveUp(EffectNames.BRIGHTNESS); |
|
411 |
} |
|
412 |
|
|
413 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
414 |
|
|
415 |
public void ButtonSaturation(View v) |
|
416 |
{ |
|
417 |
moveUp(EffectNames.SATURATION); |
|
418 |
} |
|
419 |
|
|
420 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
421 | 269 |
|
422 |
private void setBar(int id, int value) |
|
423 |
{ |
|
424 |
bar = (SeekBar)findViewById(id); |
|
425 |
bar.setOnSeekBarChangeListener(this); |
|
426 |
bar.setProgress(value); |
|
270 |
layout.removeAllViews(); |
|
271 |
mEffects.clear(); |
|
272 |
mCenter = null; |
|
427 | 273 |
} |
428 | 274 |
|
429 | 275 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
430 | 276 |
|
431 |
private void computeChroma()
|
|
277 |
private void addView(EffectNames name)
|
|
432 | 278 |
{ |
433 |
Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView); |
|
434 |
Fragment3DRenderer renderer = view.getRenderer(); |
|
435 |
|
|
436 |
fchromaL = chromaL/100.0f; |
|
437 |
fchromaR = chromaR*255/100.0f; |
|
438 |
fchromaG = chromaG*255/100.0f; |
|
439 |
fchromaB = chromaB*255/100.0f; |
|
440 |
|
|
441 |
renderer.setChroma( fchromaL, fchromaR, fchromaG, fchromaB ); |
|
279 |
Fragment3DEffect newInfo = new Fragment3DEffect(name); |
|
280 |
LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout); |
|
281 |
newInfo.addView(layout); |
|
282 |
mEffects.add(newInfo); |
|
442 | 283 |
} |
443 | 284 |
|
444 | 285 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
445 | 286 |
|
446 |
private void setChromaText()
|
|
287 |
public void Remove(View v)
|
|
447 | 288 |
{ |
448 |
fchromaL = ((int)(100*fchromaL))/100.0f; |
|
449 |
fchromaR = (float)((int)fchromaR); |
|
450 |
fchromaG = (float)((int)fchromaG); |
|
451 |
fchromaB = (float)((int)fchromaB); |
|
452 |
|
|
453 |
textChroma.setText("chroma("+fchromaL+"( "+fchromaR+" , "+fchromaG+" , "+fchromaB+" )"); |
|
289 |
removeAllViews(); |
|
454 | 290 |
} |
455 | 291 |
|
456 | 292 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
457 | 293 |
|
458 |
private void computeAlpha()
|
|
294 |
public void newChroma(View v)
|
|
459 | 295 |
{ |
460 |
Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView); |
|
461 |
|
|
462 |
falphaL = alphaL/100.0f; |
|
463 |
|
|
464 |
view.getRenderer().setAlpha(falphaL); |
|
296 |
addView(EffectNames.CHROMA); |
|
465 | 297 |
} |
466 | 298 |
|
467 | 299 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
468 | 300 |
|
469 |
private void setAlphaText()
|
|
301 |
public void newAlpha(View v)
|
|
470 | 302 |
{ |
471 |
falphaL = ((int)(100*falphaL))/100.0f; |
|
472 |
|
|
473 |
textAlpha.setText("alpha("+falphaL+")"); |
|
303 |
addView(EffectNames.ALPHA); |
|
474 | 304 |
} |
475 | 305 |
|
476 | 306 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
477 | 307 |
|
478 |
private void computeBrightness()
|
|
308 |
public void newBrightness(View v)
|
|
479 | 309 |
{ |
480 |
Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView); |
|
481 |
|
|
482 |
fbrightnessL = brightnessL/100.0f; |
|
483 |
|
|
484 |
view.getRenderer().setBrightness( fbrightnessL ); |
|
310 |
addView(EffectNames.BRIGHTNESS); |
|
485 | 311 |
} |
486 | 312 |
|
487 | 313 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
488 | 314 |
|
489 |
private void setBrightnessText()
|
|
315 |
public void newSaturation(View v)
|
|
490 | 316 |
{ |
491 |
fbrightnessL = ((int)(100*fbrightnessL))/100.0f; |
|
492 |
|
|
493 |
textBrightness.setText("brightness("+fbrightnessL+")"); |
|
317 |
addView(EffectNames.SATURATION); |
|
494 | 318 |
} |
495 | 319 |
|
496 | 320 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
497 | 321 |
|
498 |
private void computeSaturation() |
|
499 |
{ |
|
500 |
Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView); |
|
501 |
|
|
502 |
fsaturationL = saturationL/100.0f; |
|
503 |
|
|
504 |
view.getRenderer().setSaturation( fsaturationL ); |
|
505 |
} |
|
506 |
|
|
507 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
508 |
|
|
509 |
private void setSaturationText() |
|
322 |
public DistortedBitmap getCenter() |
|
510 | 323 |
{ |
511 |
fsaturationL = ((int)(100*fsaturationL))/100.0f; |
|
512 |
|
|
513 |
textSaturation.setText("saturation("+fsaturationL+")"); |
|
324 |
return mCenter; |
|
514 | 325 |
} |
515 | 326 |
|
516 | 327 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
517 | 328 |
|
518 |
private void computeCenter()
|
|
329 |
public void setCenter(DistortedBitmap center )
|
|
519 | 330 |
{ |
520 |
Fragment3DSurfaceView view = (Fragment3DSurfaceView)findViewById(R.id.fragment3dSurfaceView); |
|
521 |
|
|
522 |
fcenterX = centerX; |
|
523 |
fcenterY = centerY; |
|
524 |
|
|
525 |
view.getRenderer().setCenter( fcenterX, fcenterY ); |
|
526 |
} |
|
527 |
|
|
528 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
529 |
|
|
530 |
private void setCenterText() |
|
531 |
{ |
|
532 |
fcenterX = ((int)(100*fcenterX))/100.0f; |
|
533 |
fcenterY = ((int)(100*fcenterY))/100.0f; |
|
534 |
|
|
535 |
textCenter.setText("center("+fcenterX+","+fcenterY+")"); |
|
536 |
} |
|
537 |
|
|
538 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
539 |
|
|
540 |
public float getCenterX() |
|
541 |
{ |
|
542 |
return fcenterX; |
|
543 |
} |
|
544 |
|
|
545 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
546 |
|
|
547 |
public float getCenterY() |
|
548 |
{ |
|
549 |
return fcenterY; |
|
331 |
mCenter = center; |
|
550 | 332 |
} |
551 | 333 |
|
552 | 334 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
592 | 374 |
Distorted.onDestroy(); |
593 | 375 |
super.onDestroy(); |
594 | 376 |
} |
595 |
|
|
596 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
597 |
|
|
598 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
599 |
{ |
|
600 |
switch (bar.getId()) |
|
601 |
{ |
|
602 |
case R.id.fragment3dcenterX : centerX = progress; computeCenter() ; setCenterText() ; break; |
|
603 |
case R.id.fragment3dcenterY : centerY = progress; computeCenter() ; setCenterText() ; break; |
|
604 |
case R.id.fragment3dchromaBar1 : chromaL = progress; computeChroma() ; setChromaText() ; break; |
|
605 |
case R.id.fragment3dchromaBar2 : chromaR = progress; computeChroma() ; setChromaText() ; break; |
|
606 |
case R.id.fragment3dchromaBar3 : chromaG = progress; computeChroma() ; setChromaText() ; break; |
|
607 |
case R.id.fragment3dchromaBar4 : chromaB = progress; computeChroma() ; setChromaText() ; break; |
|
608 |
case R.id.fragment3dalphaBar1 : alphaL = progress; computeAlpha() ; setAlphaText() ; break; |
|
609 |
case R.id.fragment3dbrightnessBar1: brightnessL= progress; computeBrightness(); setBrightnessText(); break; |
|
610 |
case R.id.fragment3dsaturationBar1: saturationL= progress; computeSaturation(); setSaturationText(); break; |
|
611 |
} |
|
612 |
} |
|
613 |
|
|
614 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
615 |
|
|
616 |
public void onStartTrackingTouch(SeekBar bar) { } |
|
617 |
|
|
618 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
619 |
|
|
620 |
public void onStopTrackingTouch(SeekBar bar) { } |
|
621 | 377 |
} |
Also available in: Unified diff
Some progress with Fragment3D app - doesn't compile yet!