From abc34b899c92b1f83a683724ad9bf9dddb1fa21a Mon Sep 17 00:00:00 2001 From: uykek Date: Thu, 25 Jun 2020 16:17:28 +0200 Subject: [PATCH] Implement onCreate method of CreateSudokuActivity (for now using the button layouts of the GameActivity) --- .../ui/CreateSudokuActivity.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/CreateSudokuActivity.java b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/CreateSudokuActivity.java index de5dbde..f9e4bad 100644 --- a/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/CreateSudokuActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlysudoku/ui/CreateSudokuActivity.java @@ -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