Implement onCreate method of CreateSudokuActivity (for now using the button layouts of the GameActivity)

This commit is contained in:
uykek 2020-06-25 16:17:28 +02:00
parent b30ae90237
commit abc34b899c

View file

@ -1,12 +1,19 @@
package org.secuso.privacyfriendlysudoku.ui;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Point;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import org.secuso.privacyfriendlysudoku.controller.GameController;
import org.secuso.privacyfriendlysudoku.controller.Symbol;
import org.secuso.privacyfriendlysudoku.controller.helper.GameInfoContainer;
import org.secuso.privacyfriendlysudoku.game.GameDifficulty;
import org.secuso.privacyfriendlysudoku.game.GameType;
import org.secuso.privacyfriendlysudoku.ui.view.R;
import org.secuso.privacyfriendlysudoku.ui.view.SudokuFieldLayout;
import org.secuso.privacyfriendlysudoku.ui.view.SudokuKeyboardLayout;
@ -14,6 +21,7 @@ import org.secuso.privacyfriendlysudoku.ui.view.SudokuSpecialButtonLayout;
public class CreateSudokuActivity extends BaseActivity {
GameController gameController;
SudokuFieldLayout layout;
SudokuKeyboardLayout keyboard;
SudokuSpecialButtonLayout specialButtonLayout;
@ -22,12 +30,41 @@ public class CreateSudokuActivity extends BaseActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
gameController = new GameController(sharedPref, getApplicationContext());
if(sharedPref.getBoolean("pref_keep_screen_on", true)) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
Bundle extras = getIntent().getExtras();
GameType gameType = GameType.valueOf(extras.getString("gameType", GameType.Default_9x9.name()));
int sectionSize = gameType.getSize();
int boardSize = sectionSize * sectionSize;
GameInfoContainer container = new GameInfoContainer(0, GameDifficulty.Unspecified,
gameType, new int [boardSize], new int [boardSize], new boolean [boardSize][sectionSize]);
gameController.loadLevel(container);
setContentView(R.layout.activity_game_view);
layout = (SudokuFieldLayout)findViewById(R.id.sudokuLayout);
layout.setSettingsAndGame(sharedPref, gameController);
keyboard = (SudokuKeyboardLayout) findViewById(R.id.sudokuKeyboardLayout);
keyboard.removeAllViews();
keyboard.setGameController(gameController);
Point p = new Point();
getWindowManager().getDefaultDisplay().getSize(p);
int orientation = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ?
LinearLayout.HORIZONTAL : LinearLayout.VERTICAL;
keyboard.setKeyBoard(gameController.getSize(), p.x,layout.getHeight()-p.y, orientation);
specialButtonLayout = (SudokuSpecialButtonLayout) findViewById(R.id.sudokuSpecialLayout);
specialButtonLayout.setButtons(p.x, gameController, keyboard, getFragmentManager(), orientation, CreateSudokuActivity.this);
gameController.notifyHighlightChangedListeners();
}
@Override