public class MainActivity extends ActionBarActivity {
final Context context = this;
//Original Colors (Hardcodeded for nice looks)
int r1c = Color.parseColor("#ff00eeff");
int r2c = Color.parseColor("#ff21ff2e");
//Final Colors Random
int r1f = randomColor();
int r2f = randomColor();
//Get int for progress
int progress = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final View r1 = (View) findViewById(R.id.r1);
final View r2 = (View) findViewById(R.id.r2);
final SeekBar bar = (SeekBar) findViewById(R.id.seekBar);
bar.setProgress(0);
bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
progress = bar.getProgress();
updateColors(r1,r1c,r1f);
updateColors(r2,r2c,r2f);
//updateColors(r1,r1c,r1f); Grey in this case TODO automatic
}
});
}
public void updateColors(View v, int ogcolor, int fcolor) {
ArgbEvaluator getColorAtPos = new ArgbEvaluator();
float percent = (float) progress / 100; //Does this return float expected between 0.0 and 1.0 ???? Im new to java so not sure
v.setBackgroundColor((Integer) getColorAtPos.evaluate(percent, ogcolor, fcolor));
v.invalidate();
}
int randomColor() {
Random rand = new Random();
int r = (int) rand.nextInt(255);
int g = (int) rand.nextInt(255);
int b = (int) rand.nextInt(255);
int color = Color.argb(255,r, g, b);
return color;
}
}
Я описал больше всего в комментариях в коде, но еще раз, когда я перемещаю Seekbar , OnProgressChanged успешно называется, а также UpdateColors называется, но я не вижу, чтобы цвет был изменен на активности.
final View r1 = (View) findViewById(R.id.r1); final View r2 = (View) findViewById(R.id.r2);
final SeekBar bar = (SeekBar) findViewById(R.id.seekBar); bar.setProgress(0); bar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) {}
@Override public void onStartTrackingTouch(SeekBar seekBar) {}
@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { progress = bar.getProgress(); updateColors(r1,r1c,r1f); updateColors(r2,r2c,r2f);
//updateColors(r1,r1c,r1f); Grey in this case TODO automatic }
}); }
public void updateColors(View v, int ogcolor, int fcolor) { ArgbEvaluator getColorAtPos = new ArgbEvaluator();
float percent = (float) progress / 100; //Does this return float expected between 0.0 and 1.0 ???? Im new to java so not sure v.setBackgroundColor((Integer) getColorAtPos.evaluate(percent, ogcolor, fcolor)); v.invalidate(); }
int randomColor() { Random rand = new Random(); int r = (int) rand.nextInt(255); int g = (int) rand.nextInt(255); int b = (int) rand.nextInt(255); int color = Color.argb(255,r, g, b); return color; }
} [/code]
Я описал больше всего в комментариях в коде, но еще раз, когда я перемещаю Seekbar , OnProgressChanged успешно называется, а также UpdateColors называется, но я не вижу, чтобы цвет был изменен на активности.