Advertisement
Swaster

MainActivity.java

Jan 17th, 2025 (edited)
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.08 KB | None | 0 0
  1. import android.os.Bundle;
  2. import android.widget.Button;
  3. import android.widget.EditText;
  4. import android.widget.TextView;
  5.  
  6. import androidx.activity.EdgeToEdge;
  7. import androidx.appcompat.app.AppCompatActivity;
  8. import androidx.core.graphics.Insets;
  9. import androidx.core.view.ViewCompat;
  10. import androidx.core.view.WindowInsetsCompat;
  11.  
  12. public class MainActivity extends AppCompatActivity {
  13.  
  14.     private static boolean isHooverOn = false;
  15.  
  16.     @Override
  17.     protected void onCreate(Bundle savedInstanceState) {
  18.         super.onCreate(savedInstanceState);
  19.         EdgeToEdge.enable(this);
  20.         setContentView(R.layout.activity_main);
  21.         ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
  22.             Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
  23.             v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
  24.             return insets;
  25.         });
  26.  
  27.  
  28.         EditText programInput = this.findViewById(R.id.program_input);
  29.         TextView programDisplay = this.findViewById(R.id.washing_display);
  30.         Button washingMachineButton = this.findViewById(R.id.washing_button);
  31.         washingMachineButton.setOnClickListener((current) -> {
  32.             try {
  33.                 int program = Integer.parseInt(programInput.getText().toString());
  34.                 if(program >= 1 && program <= 12) {
  35.                     programDisplay.setText("Numer prania: "+program);
  36.                 }
  37.             } catch (Exception ignored) {
  38.  
  39.             }
  40.         });
  41.  
  42.         Button hooverButton = this.findViewById(R.id.hoover_toggle);
  43.         TextView enabledText = this.findViewById(R.id.hoover_state);
  44.         hooverButton.setOnClickListener(v -> {
  45.             isHooverOn = !isHooverOn;
  46.  
  47.             if(isHooverOn) {
  48.                 enabledText.setText("Odkurzacz włączony");
  49.                 hooverButton.setText("WYŁĄCZ");
  50.             } else {
  51.                 enabledText.setText("Odkurzacz wyłączony");
  52.                 hooverButton.setText("WŁĄCZ");
  53.             }
  54.  
  55.         });
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement