package com.example.oliwkacodingrgb; import androidx.appcompat.app.AppCompatActivity; import android.graphics.Color; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.view.View; import android.widget.EditText; import android.widget.SeekBar; import java.util.Random; public class MainActivity extends AppCompatActivity { int r,g,b; View kwadracik; EditText wypisz1, wypisz2, wypisz3; SeekBar seekbar1, seekbar2, seekbar3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); kwadracik = findViewById(R.id.kwadracik); wypisz1 = findViewById(R.id.test); seekbar1 = (SeekBar) findViewById(R.id.seekBar1); seekbar1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekbar1) { } @Override public void onStartTrackingTouch(SeekBar seekbar1) { } @Override public void onProgressChanged(SeekBar seekbar1, int progress,boolean fromUser) { // TODO Auto-generated method stub r=progress; wypisz1.setText(String.valueOf(r)); kwadracik.setBackgroundColor(Color.rgb(r, g, b)); } }); wypisz2 = findViewById(R.id.test2); seekbar2 = (SeekBar) findViewById(R.id.seekBar2); seekbar2.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekbar2) { } @Override public void onStartTrackingTouch(SeekBar seekbar2) { } @Override public void onProgressChanged(SeekBar seekbar2, int progress,boolean fromUser) { g=progress; wypisz2.setText(String.valueOf(g)); kwadracik.setBackgroundColor(Color.rgb(r, g, b)); } }); wypisz3 = findViewById(R.id.test3); seekbar3 = (SeekBar) findViewById(R.id.seekBar3); seekbar3.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekbar3) { } @Override public void onStartTrackingTouch(SeekBar seekbar3) { } @Override public void onProgressChanged(SeekBar seekbar3, int progress,boolean fromUser) { b=progress; wypisz3.setText(String.valueOf(b)); kwadracik.setBackgroundColor(Color.rgb(r, g, b)); } }); wypisz1.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { String value= wypisz1.getText().toString(); int finalValue=Integer.parseInt(value); seekbar1.setProgress(finalValue); } }); wypisz2.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { String value= wypisz2.getText().toString(); int finalValue=Integer.parseInt(value); seekbar2.setProgress(finalValue); } }); wypisz3.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { String value= wypisz3.getText().toString(); int finalValue=Integer.parseInt(value); seekbar3.setProgress(finalValue); } }); } public void losowanie(View view) { Random ran = new Random(); int r = ran.nextInt(256); int g = ran.nextInt(256); int b = ran.nextInt(256); seekbar1.setProgress(r); seekbar2.setProgress(g); seekbar3.setProgress(b); kwadracik.setBackgroundColor(Color.rgb(r, g, b)); } }