super.onCreate(savedInstanceState);
getWindow().setBackgroundDrawable(new ColorDrawable(0xff000000));
SeekBar slider = new SeekBar(this);
LinearLayout container = new LinearLayout(this);
container.setOrientation(LinearLayout.VERTICAL);
setContentView(container);
container.addView(slider);
slider.setMax(100);
slider.setProgress(50);
FrameLayout frame = new FrameLayout(this);
final RenderingView gpuView = new RenderingView(this, Color.GREEN);
frame.addView(gpuView);
final RenderingView swView = new RenderingView(this, Color.RED);
swView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
frame.addView(swView);
container.addView(frame);
slider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
mSeekValue = (float)progress / 100.0f;
float gpuAlpha = Math.min(2.0f * mSeekValue, 1f);
gpuView.setAlpha(gpuAlpha);
float swAlpha = Math.min((1 - mSeekValue) * 2.0f, 1f);
System.out.println("(gpuAlpha, swAlpha = " + gpuAlpha + ", " + swAlpha);
swView.setAlpha(swAlpha);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});