|
| 1 | +package com.example.sudoku; |
| 2 | + |
| 3 | +import androidx.appcompat.app.AppCompatActivity; |
| 4 | + |
| 5 | +import android.content.Intent; |
| 6 | +import android.media.Image; |
| 7 | +import android.os.Bundle; |
| 8 | +import android.view.View; |
| 9 | +import android.widget.ImageButton; |
| 10 | +import android.widget.LinearLayout; |
| 11 | + |
| 12 | +public class ChooseLevel extends AppCompatActivity { |
| 13 | + |
| 14 | + private int i = 0; |
| 15 | + |
| 16 | + private void disableButtons() { |
| 17 | + LinearLayout easy = (LinearLayout) findViewById(R.id.easylevel); |
| 18 | + LinearLayout medium = (LinearLayout) findViewById(R.id.mediumlevel); |
| 19 | + LinearLayout hard = (LinearLayout) findViewById(R.id.hardlevel); |
| 20 | + LinearLayout devil = (LinearLayout) findViewById(R.id.devil_level); |
| 21 | + easy.setClickable(false); |
| 22 | + easy.setFocusable(false); |
| 23 | + medium.setClickable(false); |
| 24 | + medium.setFocusable(false); |
| 25 | + hard.setClickable(false); |
| 26 | + hard.setFocusable(false); |
| 27 | + devil.setClickable(false); |
| 28 | + devil.setFocusable(false); |
| 29 | + } |
| 30 | + |
| 31 | + @Override |
| 32 | + protected void onCreate(Bundle savedInstanceState) { |
| 33 | + super.onCreate(savedInstanceState); |
| 34 | + setContentView(R.layout.activity_choose_level); |
| 35 | + LinearLayout easy = findViewById(R.id.easylevel); |
| 36 | + LinearLayout medium = findViewById(R.id.mediumlevel); |
| 37 | + LinearLayout hard = findViewById(R.id.hardlevel); |
| 38 | + LinearLayout devil = findViewById(R.id.devil_level); |
| 39 | + |
| 40 | + LinearLayout[] layouts = new LinearLayout[]{easy, medium, hard, devil}; |
| 41 | + for (; i < layouts.length; i++) { |
| 42 | + final int value = i * 10 + 20; |
| 43 | + layouts[i].setOnClickListener(new View.OnClickListener() { |
| 44 | + @Override |
| 45 | + public void onClick(View v) { |
| 46 | + disableButtons(); |
| 47 | + Intent intent = new Intent(ChooseLevel.this, SudokuNine.class); |
| 48 | + intent.putExtra("level", value); |
| 49 | + startActivity(intent); |
| 50 | + } |
| 51 | + }); |
| 52 | + LinearLayout subLinear = (LinearLayout) layouts[i].getChildAt(1); |
| 53 | + for (int t = 0; t < subLinear.getChildCount(); t++) { |
| 54 | + ImageButton imageButton = (ImageButton) subLinear.getChildAt(t); |
| 55 | + imageButton.setOnClickListener(new View.OnClickListener() { |
| 56 | + @Override |
| 57 | + public void onClick(View v) { |
| 58 | + disableButtons(); |
| 59 | + Intent intent = new Intent(ChooseLevel.this, SudokuNine.class); |
| 60 | + intent.putExtra("level", value); |
| 61 | + startActivity(intent); |
| 62 | + } |
| 63 | + }); |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments