1) Change of the displayed stars (no stars selected) if CheckBox is set to true.

2.)Selecting the playButton starts a new CreateSudoku Intent.
3.)Additionally the button label was changed (CREATE) and "Custom Sudoku" is displayed as difficulty level.
This commit is contained in:
ErikWaegerle 2020-07-22 02:10:15 +02:00
parent 77520b0d72
commit 89baff374f

View file

@ -30,6 +30,8 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;
@ -148,17 +150,34 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
final LinkedList<GameDifficulty> difficultyList = GameDifficulty.getValidDifficultyList();
difficultyBar.setNumStars(difficultyList.size());
difficultyBar.setMax(difficultyList.size());
CheckBox createGameBar = (CheckBox) findViewById(R.id.circleButton);
difficultyBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
if (rating < 1) {
ratingBar.setRating(1);
}
createGameBar.setChecked(false);
((Button) findViewById(R.id.playButton)).setText("New Game");
if (rating >= 1) {
difficultyText.setText(getString(difficultyList.get((int) ratingBar.getRating() - 1).getStringResID()));
} else {
difficultyText.setText("Custom Sudoku");
}
}
});
createGameBar.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
difficultyBar.setRating(0);
((Button)findViewById(R.id.playButton)).setText("Create");
}
createGameBar.setChecked(isChecked);
}});
GameDifficulty lastChosenDifficulty = GameDifficulty.valueOf(settings.getString("lastChosenDifficulty", "Moderate"));
difficultyBar.setRating(GameDifficulty.getValidDifficultyList().indexOf(lastChosenDifficulty) + 1);
//difficultyBar.setRating(GameDifficulty.getValidDifficultyList().indexOf(lastChosenDifficulty) + 1);
/*LayerDrawable stars = (LayerDrawable)difficultyBar.getProgressDrawable();
stars.getDrawable(2).setColorFilter(getResources().getColor(R.color.colorPrimary), PorterDuff.Mode.SRC_ATOP);//Color for Stars fully selected
stars.getDrawable(1).setColorFilter(getResources().getColor(R.color.middleblue), PorterDuff.Mode.SRC_ATOP);//Color for Stars partially selected
@ -193,8 +212,6 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
winScreen.show(fm,"win_screen_layout");*/
}
public void onClick(View view) {
Intent i = null;
@ -211,6 +228,13 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
break;
case R.id.playButton:
GameType gameType = GameType.getValidGameTypes().get(mViewPager.getCurrentItem());
if (((CheckBox)findViewById(R.id.circleButton)).isChecked()) {
// send everything to game activity
i = new Intent(this, CreateSudokuActivity.class);
i.putExtra("gameType", gameType.name());
//i.putExtra("gameDifficulty", GameDifficulty.Easy);
break;
}
int index = difficultyBar.getProgress()-1;
GameDifficulty gameDifficulty = GameDifficulty.getValidDifficultyList().get(index < 0 ? 0 : index);