diff --git a/app/src/androidTest/java/tu_darmstadt/sudoku/view/ApplicationTest.java b/app/src/androidTest/java/tu_darmstadt/sudoku/view/ApplicationTest.java index 03dfa6e..14f8c61 100644 --- a/app/src/androidTest/java/tu_darmstadt/sudoku/view/ApplicationTest.java +++ b/app/src/androidTest/java/tu_darmstadt/sudoku/view/ApplicationTest.java @@ -1,4 +1,4 @@ -package tu_darmstadt.sudoku.view; +package tu_darmstadt.sudoku.ui.view; import android.app.Application; import android.test.ApplicationTestCase; diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5aedd69..938bcea 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ + package="tu_darmstadt.sudoku.ui.view" > - + @@ -16,18 +16,19 @@ + android:parentActivityName="tu_darmstadt.sudoku.ui.MainActivity" > + android:value="tu_darmstadt.sudoku.ui.MainActivity" /> - + + diff --git a/app/src/main/java/tu_darmstadt/sudoku/controller/GameController.java b/app/src/main/java/tu_darmstadt/sudoku/controller/GameController.java index 1ece34b..073d851 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/controller/GameController.java +++ b/app/src/main/java/tu_darmstadt/sudoku/controller/GameController.java @@ -1,5 +1,7 @@ package tu_darmstadt.sudoku.controller; +import android.content.SharedPreferences; + import java.util.LinkedList; import java.util.List; @@ -7,10 +9,8 @@ import tu_darmstadt.sudoku.game.CellConflict; import tu_darmstadt.sudoku.game.CellConflictList; import tu_darmstadt.sudoku.game.GameCell; import tu_darmstadt.sudoku.game.GameField; -import tu_darmstadt.sudoku.game.GameSettings; import tu_darmstadt.sudoku.game.GameType; -import tu_darmstadt.sudoku.game.ICellAction; -import tu_darmstadt.sudoku.game.solver.Default9x9Solver; +import tu_darmstadt.sudoku.game.solver.Solver; import tu_darmstadt.sudoku.game.solver.ISolver; /** @@ -26,21 +26,26 @@ public class GameController { private GameType gameType; private int selectedRow; private int selectedCol; + private SharedPreferences settings; private CellConflictList errorList = new CellConflictList(); - private GameSettings settings = new GameSettings(); //private LinkedList listeners = new LinkedList<>(); -// private Default9x9Solver solver; +// private Solver solver; // private SudokuGenerator generator; - public GameController() { - this(GameType.Default_9x9); + public GameController(SharedPreferences pref) { + this(GameType.Default_9x9, pref); } - public GameController(GameType type) { + public GameController() { + this(null); + } + + public GameController(GameType type, SharedPreferences pref) { this.gameType = type; setGameType(type); gameField = new GameField(size, sectionHeight, sectionWidth); + setSettings(pref); setValue(0, 1, 8); setValue(0, 4, 2); setValue(0, 5, 6); setValue(0, 6, 7); setValue(0, 7, 3); setValue(0, 8, 4); @@ -53,10 +58,31 @@ public class GameController { setNote(7, 3, 9); } + public void loadLevel(int size, int sectionHeight, int sectionWidth, int[] fixedValues, int[] setValues, int[][] setNotes) { + this.size = size; + this.sectionHeight = sectionHeight; + this.sectionWidth = sectionWidth; + this.gameField = new GameField(size, sectionHeight, sectionWidth); + gameField.initCells(fixedValues); + + // now set the values that are not fixed + for(int i = 0; i < size*size; i++) { + int row = (int)Math.floor(i/size); + int col = i%size; + setValue(row, col, setValues[i]); + } + } + + public void setSettings(SharedPreferences pref) { + settings = pref; + } + private GameField solve(GameField gameField) { switch(gameType) { case Default_9x9: - solver = new Default9x9Solver(gameField); + case Default_6x6: + case Default_12x12: + solver = new Solver(gameField); break; default: throw new UnsupportedOperationException("No Solver for this GameType defined."); @@ -116,7 +142,7 @@ public class GameController { cell.deleteNotes(); cell.setValue(value); - if(settings.getEnableAutomaticNoteDeletion()) { + if(settings != null && settings.getBoolean("pref_automatic_note_deletion",true)) { LinkedList updateList = new LinkedList(); updateList.addAll(gameField.getRow(cell.getRow())); updateList.addAll(gameField.getColumn(cell.getCol())); @@ -126,7 +152,7 @@ public class GameController { } } - public LinkedList getConnectedCells(int row, int col, boolean connectedSec, boolean connectedRow, boolean connectedCol) { + public LinkedList getConnectedCells(int row, int col, boolean connectedRow, boolean connectedCol, boolean connectedSec) { LinkedList list = new LinkedList<>(); if(connectedRow) list.addAll(gameField.getRow(row)); diff --git a/app/src/main/java/tu_darmstadt/sudoku/game/GameField.java b/app/src/main/java/tu_darmstadt/sudoku/game/GameField.java index 43a4ef3..7b1ddeb 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/game/GameField.java +++ b/app/src/main/java/tu_darmstadt/sudoku/game/GameField.java @@ -23,7 +23,7 @@ public class GameField implements Cloneable { this.size = size; field = new GameCell[size][size]; - initCells(null); + initCells(new int[][]{{1}}); } public void reset() { @@ -58,6 +58,18 @@ public class GameField implements Cloneable { } } + public void initCells(int[] level) { + if(level.length != size*size) { + throw new IllegalArgumentException("Levelarray must have length of "+size*size+"."); + } + // Initit the game field with a 1 dimension array + for(int i = 0; i < size*size; i++) { + int row = (int)Math.floor(i/size); + int col = i%size; + field[row][col] = new GameCell(row,col,size,level[i]); + } + } + public GameCell getCell(int row, int col) { return field[row][col]; } diff --git a/app/src/main/java/tu_darmstadt/sudoku/game/solver/Default9x9Solver.java b/app/src/main/java/tu_darmstadt/sudoku/game/solver/Solver.java similarity index 57% rename from app/src/main/java/tu_darmstadt/sudoku/game/solver/Default9x9Solver.java rename to app/src/main/java/tu_darmstadt/sudoku/game/solver/Solver.java index 668783c..3c2cfbd 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/game/solver/Default9x9Solver.java +++ b/app/src/main/java/tu_darmstadt/sudoku/game/solver/Solver.java @@ -1,5 +1,7 @@ package tu_darmstadt.sudoku.game.solver; +import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -11,11 +13,11 @@ import tu_darmstadt.sudoku.game.ICellAction; /** * Created by Chris on 10.11.2015. */ -public class Default9x9Solver implements ISolver { +public class Solver implements ISolver { private GameField gameField = null; - public Default9x9Solver(GameField gf) { + public Solver(GameField gf) { try { if(gf == null) { throw new IllegalArgumentException("GameField may not be null."); @@ -31,6 +33,17 @@ public class Default9x9Solver implements ISolver { throw new IllegalArgumentException("This GameField is not solveable."); } + setNotes(gameField); + } + + public void setNotes(GameField gameField) { + for(int i = 0; i < gameField.getSize(); i++) { + for(int j = 0; j < gameField.getSize(); j++) { + for(int k = 0; k < gameField.getSize(); k++) { + gameField.getCell(i,j).setNote(k); + } + } + } } public boolean isSolvable(GameField gameField) { @@ -110,6 +123,69 @@ public class Default9x9Solver implements ISolver { return false; } + private boolean searchHiddenSingles() { + boolean foundHiddenSingles = false; + + LinkedList list = new LinkedList<>(); + + for(int i = 0; i < gameField.getSize()*3; i++) { + + int index = i % gameField.getSize(); + int listSelector = (int)Math.floor(i / gameField.getSize()); + + if(listSelector == 0) list = gameField.getRow(index); + if(listSelector == 1) list = gameField.getColumn(index); + if(listSelector == 2) list = gameField.getSection(index); + + LinkedList possibles = new LinkedList<>(); + LinkedList notPossibles = new LinkedList(); + + for(GameCell c : list) { // check all gameCells in Row + + if(c.hasValue()) { + notPossibles.add(c.getValue()); + continue; + } + + for(int k = 0; k < gameField.getSize(); k++) { // check all nodes + if(c.getNotes()[k]) { // if k note active + for(int p = 0; p < possibles.size(); p++) { // check possible list + if(possibles.get(p)[2] == k+1) { // is value in possible list? + // value already exists in possible list + // add to impossibles + if(!notPossibles.contains(k+1)) { + notPossibles.add(k + 1); + } + } + } + if(!notPossibles.contains(k+1)){ // if k node is possible + possibles.add(new Integer[] {c.getRow(), c.getCol(), k+1}); + } + } + } + } + // we checked a section/row/column + // now set the remaining possibles that are not impossible + boolean possible = true; + for(int p = 0; p < possibles.size(); p++) { + possible = true; + for(int np = 0; np < notPossibles.size(); np++) { + if(possibles.get(p)[2] == notPossibles.get(np)) { + // found that current possible is impossible + possible = false; + } + } + // if this is still possible then SET IT :D YAY + if(possible) { + gameField.getCell(possibles.get(p)[0],possibles.get(p)[1]).setValue(possibles.get(p)[2]); + foundHiddenSingles = true; + } + } + } + + return foundHiddenSingles; + } + public boolean searchNakedPairsTriples() { return false; } @@ -145,9 +221,5 @@ public class Default9x9Solver implements ISolver { }}, false); } - private boolean searchHiddenSingles() { - return false; - } - } diff --git a/app/src/main/java/tu_darmstadt/sudoku/ui/AboutActivity.java b/app/src/main/java/tu_darmstadt/sudoku/ui/AboutActivity.java new file mode 100644 index 0000000..757637c --- /dev/null +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/AboutActivity.java @@ -0,0 +1,35 @@ +package tu_darmstadt.sudoku.ui; + +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.MenuItem; + +import tu_darmstadt.sudoku.ui.view.R; + +public class AboutActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_about); + + android.support.v7.app.ActionBar actionBar = getSupportActionBar(); + actionBar.setTitle(R.string.about); + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#024265"))); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + // Respond to the action bar's Up/Home button + case android.R.id.home: + finish(); + return true; + } + return super.onOptionsItemSelected(item); + } + +} diff --git a/app/src/main/java/tu_darmstadt/sudoku/view/AppCompatPreferenceActivity.java b/app/src/main/java/tu_darmstadt/sudoku/ui/AppCompatPreferenceActivity.java similarity index 98% rename from app/src/main/java/tu_darmstadt/sudoku/view/AppCompatPreferenceActivity.java rename to app/src/main/java/tu_darmstadt/sudoku/ui/AppCompatPreferenceActivity.java index 958a856..513ea9a 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/view/AppCompatPreferenceActivity.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/AppCompatPreferenceActivity.java @@ -1,4 +1,4 @@ -package tu_darmstadt.sudoku.view; +package tu_darmstadt.sudoku.ui; import android.content.res.Configuration; import android.os.Bundle; diff --git a/app/src/main/java/tu_darmstadt/sudoku/view/GameActivity.java b/app/src/main/java/tu_darmstadt/sudoku/ui/GameActivity.java similarity index 73% rename from app/src/main/java/tu_darmstadt/sudoku/view/GameActivity.java rename to app/src/main/java/tu_darmstadt/sudoku/ui/GameActivity.java index 738a416..dbb86af 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/view/GameActivity.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/GameActivity.java @@ -1,8 +1,9 @@ -package tu_darmstadt.sudoku.view; +package tu_darmstadt.sudoku.ui; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; -import android.support.annotation.Nullable; +import android.preference.PreferenceManager; import android.support.design.widget.NavigationView; import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; @@ -11,26 +12,31 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; -import android.view.ViewGroup; import tu_darmstadt.sudoku.controller.GameController; import tu_darmstadt.sudoku.game.*; +import tu_darmstadt.sudoku.ui.view.R; +import tu_darmstadt.sudoku.ui.view.SudokuFieldLayout; public class GameActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { - GameController gameController = new GameController(GameType.Default_9x9); + GameController gameController; SudokuFieldLayout layout; - - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); + setContentView(R.layout.activity_game_view); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); layout = (SudokuFieldLayout)findViewById(R.id.sudokuLayout); + + gameController = new GameController(GameType.Default_9x9, sharedPref); layout.setGame(gameController); + layout.setSettings(sharedPref); /* // DEBUG String debug = gameController.getFieldAsString(); @@ -75,8 +81,11 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On if (id == R.id.nav_newgame) { //create new game + //intent = new Intent(this, NewGameActivity.class); + //startActivity(intent); + } else if (id == R.id.nav_mainmenu) { - //new Game + //go to main menu intent = new Intent(this, MainActivity.class); startActivity(intent); @@ -85,15 +94,19 @@ public class GameActivity extends AppCompatActivity implements NavigationView.On intent = new Intent(this,SettingsActivity.class); startActivity(intent); - - } else if (id == R.id.nav_highscore) { - //open highscore - - // } else if (id == R.id.nav_share) { - - // } else if (id == R.id.nav_send) { + // see highscore list + //intent = new Intent(this, HighscoreActivity.class); + //startActivity(intent); + } else if (id == R.id.nav_about) { + //open about page + intent = new Intent(this,AboutActivity.class); + startActivity(intent); + } else if (id == R.id.nav_help) { + //open about page + //intent = new Intent(this,HelpActivity.class); + //startActivity(intent); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); diff --git a/app/src/main/java/tu_darmstadt/sudoku/view/MainActivity.java b/app/src/main/java/tu_darmstadt/sudoku/ui/MainActivity.java similarity index 87% rename from app/src/main/java/tu_darmstadt/sudoku/view/MainActivity.java rename to app/src/main/java/tu_darmstadt/sudoku/ui/MainActivity.java index 8c4129c..ecf1d93 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/view/MainActivity.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/MainActivity.java @@ -1,10 +1,11 @@ -package tu_darmstadt.sudoku.view; +package tu_darmstadt.sudoku.ui; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; -import android.widget.TextView; + +import tu_darmstadt.sudoku.ui.view.R; public class MainActivity extends AppCompatActivity { diff --git a/app/src/main/java/tu_darmstadt/sudoku/view/SettingsActivity.java b/app/src/main/java/tu_darmstadt/sudoku/ui/SettingsActivity.java similarity index 63% rename from app/src/main/java/tu_darmstadt/sudoku/view/SettingsActivity.java rename to app/src/main/java/tu_darmstadt/sudoku/ui/SettingsActivity.java index 029335f..680d1f7 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/view/SettingsActivity.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/SettingsActivity.java @@ -1,4 +1,4 @@ -package tu_darmstadt.sudoku.view; +package tu_darmstadt.sudoku.ui; import android.annotation.TargetApi; @@ -19,9 +19,8 @@ import android.preference.PreferenceManager; import android.preference.RingtonePreference; import android.text.TextUtils; import android.view.MenuItem; -import android.support.v4.app.NavUtils; -import tu_darmstadt.sudoku.view.R; +import tu_darmstadt.sudoku.ui.view.R; import java.util.List; @@ -59,7 +58,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity { int id = item.getItemId(); if (id == android.R.id.home) { if (!super.onMenuItemSelected(featureId, item)) { - NavUtils.navigateUpFromSameTask(this); + finish(); + //NavUtils.navigateUpFromSameTask(this); } return true; } @@ -114,28 +114,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity { ? listPreference.getEntries()[index] : null); - } else if (preference instanceof RingtonePreference) { - // For ringtone preferences, look up the correct display value - // using RingtoneManager. - if (TextUtils.isEmpty(stringValue)) { - // Empty values correspond to 'silent' (no ringtone). - preference.setSummary(R.string.pref_ringtone_silent); - - } else { - Ringtone ringtone = RingtoneManager.getRingtone( - preference.getContext(), Uri.parse(stringValue)); - - if (ringtone == null) { - // Clear the summary if there was a lookup error. - preference.setSummary(null); - } else { - // Set the summary to reflect the new ringtone display - // name. - String name = ringtone.getTitle(preference.getContext()); - preference.setSummary(name); - } - } - } else { // For all other preferences, set the summary to the value's // simple string representation. @@ -172,9 +150,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity { */ protected boolean isValidFragment(String fragmentName) { return PreferenceFragment.class.getName().equals(fragmentName) - || GeneralPreferenceFragment.class.getName().equals(fragmentName) - || DataSyncPreferenceFragment.class.getName().equals(fragmentName) - || NotificationPreferenceFragment.class.getName().equals(fragmentName); + || GamePreferenceFragment.class.getName().equals(fragmentName) + || HighlightingPreferenceFragment.class.getName().equals(fragmentName); } /** @@ -182,7 +159,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { * activity is showing a two-pane settings UI. */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public static class GeneralPreferenceFragment extends PreferenceFragment { + public static class GamePreferenceFragment extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -193,8 +170,9 @@ public class SettingsActivity extends AppCompatPreferenceActivity { // to their values. When their values change, their summaries are // updated to reflect the new value, per the Android Design // guidelines. - bindPreferenceSummaryToValue(findPreference("example_text")); - bindPreferenceSummaryToValue(findPreference("example_list")); + + //bindPreferenceSummaryToValue(findPreference("example_text")); + //bindPreferenceSummaryToValue(findPreference("example_list")); } @@ -202,7 +180,8 @@ public class SettingsActivity extends AppCompatPreferenceActivity { public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == android.R.id.home) { - startActivity(new Intent(getActivity(), SettingsActivity.class)); + getActivity().finish(); + //startActivity(new Intent(getActivity(), SettingsActivity.class)); return true; } return super.onOptionsItemSelected(item); @@ -214,64 +193,9 @@ public class SettingsActivity extends AppCompatPreferenceActivity { * activity is showing a two-pane settings UI. */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public static class NotificationPreferenceFragment extends PreferenceFragment { + public static class HighlightingPreferenceFragment extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.pref_notification); - setHasOptionsMenu(true); - - // Bind the summaries of EditText/List/Dialog/Ringtone preferences - // to their values. When their values change, their summaries are - // updated to reflect the new value, per the Android Design - // guidelines. - bindPreferenceSummaryToValue(findPreference("notifications_new_message_ringtone")); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int id = item.getItemId(); - if (id == android.R.id.home) { - startActivity(new Intent(getActivity(), SettingsActivity.class)); - return true; - } - return super.onOptionsItemSelected(item); - } - } - - /** - * This fragment shows data and sync preferences only. It is used when the - * activity is showing a two-pane settings UI. - */ - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public static class DataSyncPreferenceFragment extends PreferenceFragment { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.pref_data_sync); - setHasOptionsMenu(true); - - // Bind the summaries of EditText/List/Dialog/Ringtone preferences - // to their values. When their values change, their summaries are - // updated to reflect the new value, per the Android Design - // guidelines. - bindPreferenceSummaryToValue(findPreference("sync_frequency")); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - int id = item.getItemId(); - if (id == android.R.id.home) { - startActivity(new Intent(getActivity(), SettingsActivity.class)); - return true; - } - return super.onOptionsItemSelected(item); - } - } - @TargetApi(Build.VERSION_CODES.HONEYCOMB) - public static class TestFragment extends PreferenceFragment { - @Override - public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.pref_highlighting); setHasOptionsMenu(true); @@ -280,18 +204,21 @@ public class SettingsActivity extends AppCompatPreferenceActivity { // to their values. When their values change, their summaries are // updated to reflect the new value, per the Android Design // guidelines. - //bindPreferenceSummaryToValue(findPreference("")); + + //bindPreferenceSummaryToValue(findPreference("highlighting_connected_rows")); + //bindPreferenceSummaryToValue(findPreference("highlighting_connected_columns")); + //bindPreferenceSummaryToValue(findPreference("highlighting_connected_sections")); } @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == android.R.id.home) { - startActivity(new Intent(getActivity(), SettingsActivity.class)); + getActivity().finish(); + //startActivity(new Intent(getActivity(), SettingsActivity.class)); return true; } return super.onOptionsItemSelected(item); } - } } diff --git a/app/src/main/java/tu_darmstadt/sudoku/view/highlighting/CellHighlightTypes.java b/app/src/main/java/tu_darmstadt/sudoku/ui/view/CellHighlightTypes.java similarity index 81% rename from app/src/main/java/tu_darmstadt/sudoku/view/highlighting/CellHighlightTypes.java rename to app/src/main/java/tu_darmstadt/sudoku/ui/view/CellHighlightTypes.java index 0fbd9fa..12a03b5 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/view/highlighting/CellHighlightTypes.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/view/CellHighlightTypes.java @@ -1,4 +1,4 @@ -package tu_darmstadt.sudoku.view.highlighting; +package tu_darmstadt.sudoku.ui.view; /** * Created by Chris on 12.11.2015. diff --git a/app/src/main/java/tu_darmstadt/sudoku/view/SudokuCellView.java b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuCellView.java similarity index 88% rename from app/src/main/java/tu_darmstadt/sudoku/view/SudokuCellView.java rename to app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuCellView.java index afdebcf..cea8d3b 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/view/SudokuCellView.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuCellView.java @@ -1,4 +1,4 @@ -package tu_darmstadt.sudoku.view; +package tu_darmstadt.sudoku.ui.view; import android.content.Context; import android.graphics.Canvas; @@ -7,16 +7,10 @@ import android.graphics.Paint; import android.graphics.RectF; import android.graphics.Typeface; import android.util.AttributeSet; -import android.view.MotionEvent; import android.view.View; import android.widget.RelativeLayout; -import android.widget.TextView; -import android.widget.Toast; - -import java.util.jar.Attributes; import tu_darmstadt.sudoku.game.GameCell; -import tu_darmstadt.sudoku.view.highlighting.CellHighlightTypes; /** * Created by TMZ_LToP on 10.11.2015. @@ -98,7 +92,10 @@ public class SudokuCellView extends View { p.setColor(Color.GREEN); break; case Connected: - p.setColor(Color.argb(55, 255, 255, 0)); + p.setColor(Color.WHITE); + drawBackground(canvas, 3, 3, mWidth - 3, mHeight - 3, p); + p.setColor(Color.YELLOW); + p.setAlpha(100); break; case Highlighted: p.setColor(Color.YELLOW); @@ -128,9 +125,9 @@ public class SudokuCellView extends View { for (int i = 0; i < mGameCell.getNotes().length; i++) { if (mGameCell.getNotes()[i]) { p.setTypeface(Typeface.SANS_SERIF); - p.setTextSize(mWidth * 3 / 12); + p.setTextSize(mWidth/4); p.setTextAlign(Paint.Align.RIGHT); - canvas.drawText(String.valueOf(i+1),(mWidth*1/12)*k,(mWidth*1/12)*j,p); + canvas.drawText(String.valueOf(i+1),(mWidth/12)*k,(mWidth/12)*j,p); k+=4; if (k > 11) { k = 3; @@ -151,7 +148,7 @@ public class SudokuCellView extends View { p.setAntiAlias(true); p.setTextSize(Math.min(mHeight * 3 / 4, mHeight * 3 / 4)); p.setTextAlign(Paint.Align.CENTER); - canvas.drawText(String.valueOf(mGameCell.getValue()), mHeight/2, mHeight/2 + mHeight/4, p); + canvas.drawText(String.valueOf(mGameCell.getValue()), mHeight / 2, mHeight / 2 + mHeight / 4, p); } public int getRow() { @@ -160,4 +157,11 @@ public class SudokuCellView extends View { public int getCol() { return mCol; } + + /*@Override + public Parcelable onSaveInstanceState() { + Parcelable state = super.onSaveInstanceState(); + + return state; + }*/ } diff --git a/app/src/main/java/tu_darmstadt/sudoku/view/SudokuFieldLayout.java b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuFieldLayout.java similarity index 85% rename from app/src/main/java/tu_darmstadt/sudoku/view/SudokuFieldLayout.java rename to app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuFieldLayout.java index a6de84b..cefd49d 100644 --- a/app/src/main/java/tu_darmstadt/sudoku/view/SudokuFieldLayout.java +++ b/app/src/main/java/tu_darmstadt/sudoku/ui/view/SudokuFieldLayout.java @@ -1,6 +1,7 @@ -package tu_darmstadt.sudoku.view; +package tu_darmstadt.sudoku.ui.view; import android.content.Context; +import android.content.SharedPreferences; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; @@ -9,12 +10,8 @@ import android.view.MotionEvent; import android.view.View; import android.widget.RelativeLayout; -import java.util.List; - import tu_darmstadt.sudoku.controller.GameController; import tu_darmstadt.sudoku.game.GameCell; -import tu_darmstadt.sudoku.game.GameSettings; -import tu_darmstadt.sudoku.view.highlighting.CellHighlightTypes; /** * Created by Timm Lippert on 11.11.2015. @@ -26,6 +23,7 @@ public class SudokuFieldLayout extends RelativeLayout { private int sectionWidth; private int gameCellWidth; private int gameCellHeight; + private SharedPreferences settings; public SudokuCellView [][] gamecells; AttributeSet attrs; @@ -36,6 +34,10 @@ public class SudokuFieldLayout extends RelativeLayout { setBackgroundColor(Color.argb(255, 200, 200, 200)); } + public void setSettings(SharedPreferences sharedPref) { + settings = sharedPref; + } + public void setGame(GameController gc) { if (gc == null) throw new IllegalArgumentException("GameController may not be null."); gameController = gc; @@ -58,7 +60,13 @@ public class SudokuFieldLayout extends RelativeLayout { } } // Set connected Fields - for(GameCell c : gameController.getConnectedCells(row,col, GameSettings.getHighlightConnectedRow(), GameSettings.getHighlightConnectedColumn(), GameSettings.getHighlightConnectedSection())) { + + //String syncConnPref = sharedPref.getString(SettingsActivity., ""); + boolean highlightConnectedRow = settings.getBoolean("pref_highlight_rows", true); + boolean highlightConnectedColumn = settings.getBoolean("pref_highlight_cols", true); + boolean highlightConnectedSection = settings.getBoolean("pref_highlight_secs", true); + + for(GameCell c : gameController.getConnectedCells(row,col, highlightConnectedRow, highlightConnectedColumn, highlightConnectedSection)) { gamecells[c.getRow()][c.getCol()].setHighlightType(CellHighlightTypes.Connected); } // Select touched Cell diff --git a/app/src/main/res/drawable-hdpi/privacyfriendlyappslogo.png b/app/src/main/res/drawable-hdpi/privacyfriendlyappslogo.png new file mode 100644 index 0000000..69f63a8 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/privacyfriendlyappslogo.png differ diff --git a/app/src/main/res/drawable-hdpi/secuso_logo_blau_blau.png b/app/src/main/res/drawable-hdpi/secuso_logo_blau_blau.png new file mode 100644 index 0000000..43a4df6 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/secuso_logo_blau_blau.png differ diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml new file mode 100644 index 0000000..bc3f9be --- /dev/null +++ b/app/src/main/res/layout/activity_about.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 886738c..c6cecfa 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -5,7 +5,7 @@ android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" - tools:context="tu_darmstadt.sudoku.view.MainActivity"> + tools:context="tu_darmstadt.sudoku.activity.MainActivity"> + tools:context="tu_darmstadt.sudoku.activity.GameActivity"> diff --git a/app/src/main/res/layout/content_game_view.xml b/app/src/main/res/layout/content_game_view.xml index fc2461d..4150aec 100644 --- a/app/src/main/res/layout/content_game_view.xml +++ b/app/src/main/res/layout/content_game_view.xml @@ -9,8 +9,8 @@ android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" app:layout_behavior="@string/appbar_scrolling_view_behavior" - tools:showIn="@layout/app_bar_game_view" tools:context="tu_darmstadt.sudoku.view.GameActivity"> - + + android:text="@string/description" android:id="@+id/textView" /> diff --git a/app/src/main/res/menu/activity_game_view_drawer.xml b/app/src/main/res/menu/activity_game_view_drawer.xml index 7e17bf4..6400c4a 100644 --- a/app/src/main/res/menu/activity_game_view_drawer.xml +++ b/app/src/main/res/menu/activity_game_view_drawer.xml @@ -2,23 +2,22 @@ - - - - - + - + - - + \ No newline at end of file diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 60cf80b..df3235d 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -17,7 +17,13 @@ Einstellungen - Auswahl + Feld Auswahl Werte + + Diese App gehört zur Gruppe der Privacy Friendly Apps. + Mehr Informationen unter: + In Zusammenarbeit mit: + Autor: \nChristopher Beckmann, Timm Lippert + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 3ab3e9c..06aeefe 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,6 +1,6 @@ - #3F51B5 - #303F9F + #024265 + #024265 #FF4081 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0ec2a5a..c25e113 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2,7 +2,7 @@ Sudoku Sudoku - + New Game Settings Highscore @@ -11,31 +11,49 @@ Help About + a privacy friendly logic puzzle + Open navigation drawer Close navigation drawer - + Settings Settings + + Highlighting - - Selection - Values + Selection highlight + Connected rows + Connected columns + Connected sections + + Value highlight + Same values + Notes + + + Game + + Game settings + Note deletion + Automatically remove notes when setting values on connected cells - - General + + Privacy friendly Sudoku + v0.1 + Author: Christopher Beckmann, Timm Lippert + In affiliation with: + This application belongs to the Privacy Friendly Apps. + More information can be found on: + https://www.secuso.org - Enable social recommendations - Recommendations for people to contact - based on your message history - - Display DeineMudda - Anonymous + - Add friends to messages + + - Data & sync - Sync frequency 15 minutes @@ -66,17 +81,5 @@ 180 360 -1 - - - System sync settings - - - Notifications - - New message notifications - - Ringtone - Silent - - Vibrate + --> diff --git a/app/src/main/res/xml/pref_data_sync.xml b/app/src/main/res/xml/pref_data_sync.xml deleted file mode 100644 index ffda831..0000000 --- a/app/src/main/res/xml/pref_data_sync.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index d7cfdc5..3e70e0f 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -1,14 +1,16 @@ - + + + - + android:maxLines="1" /> --> - + android:positiveButtonText="@null" /> --> diff --git a/app/src/main/res/xml/pref_headers.xml b/app/src/main/res/xml/pref_headers.xml index e94b4ce..59d1dfe 100644 --- a/app/src/main/res/xml/pref_headers.xml +++ b/app/src/main/res/xml/pref_headers.xml @@ -2,15 +2,12 @@ -
+
-
- diff --git a/app/src/main/res/xml/pref_highlighting.xml b/app/src/main/res/xml/pref_highlighting.xml index ff4be12..14f8851 100644 --- a/app/src/main/res/xml/pref_highlighting.xml +++ b/app/src/main/res/xml/pref_highlighting.xml @@ -1,11 +1,33 @@ - - + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_notification.xml b/app/src/main/res/xml/pref_notification.xml deleted file mode 100644 index 298ecfb..0000000 --- a/app/src/main/res/xml/pref_notification.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - diff --git a/app/src/test/java/tu_darmstadt/sudoku/ExampleUnitTest.java b/app/src/test/java/tu_darmstadt/sudoku/ExampleUnitTest.java index 8d1e3e6..3dcb8fd 100644 --- a/app/src/test/java/tu_darmstadt/sudoku/ExampleUnitTest.java +++ b/app/src/test/java/tu_darmstadt/sudoku/ExampleUnitTest.java @@ -1,4 +1,4 @@ -package tu_darmstadt.sudoku.view; +package tu_darmstadt.sudoku.ui.view; import org.junit.Test; diff --git a/app/src/test/java/tu_darmstadt/sudoku/game/solver/SolverTest.java b/app/src/test/java/tu_darmstadt/sudoku/game/solver/SolverTest.java index f2c3a46..9745627 100644 --- a/app/src/test/java/tu_darmstadt/sudoku/game/solver/SolverTest.java +++ b/app/src/test/java/tu_darmstadt/sudoku/game/solver/SolverTest.java @@ -28,6 +28,10 @@ public class SolverTest { { 7, 0, 0, 0, 1, 0, 3, 0, 5 }}; } + //000041000060000200000000000320600000000050041700000000000200300048000000501000000 + + //501900000200004950390700026030001072006057000072009041000070409640000000700010305 + @Test public void solveTest() { }