public void removePossibles(GridCell selectedCell) { ArrayList<GridCell> possibleCells = this.kenKenGrid.getPossiblesInRowCol(selectedCell); for (GridCell cell : possibleCells) { saveUndo(cell, true); cell.removePossible(selectedCell.getUserValue()); } }
public boolean onContextItemSelected(MenuItem item) { GridCell selectedCell = this.kenKenGrid.mSelectedCell; if (selectedCell == null) return super.onContextItemSelected(item); switch (item.getItemId()) { case R.id.menu_show_mistakes: this.kenKenGrid.markInvalidChoices(); return true; case R.id.menu_reveal_cell: selectedCell.setUserValue(selectedCell.mValue); selectedCell.mCheated = true; this.kenKenGrid.invalidate(); break; case R.id.menu_reveal_cage: this.kenKenGrid.Solve(false, true); break; case R.id.menu_show_solution: this.kenKenGrid.Solve(true, true); break; } Toast.makeText(this, R.string.toast_cheated, Toast.LENGTH_SHORT).show(); storeStreak(false); return super.onContextItemSelected(item); }
public void restoreUndo() { if (!undoList.isEmpty()) { UndoState undoState = undoList.removeLast(); GridCell cell = kenKenGrid.mCells.get(undoState.getCellNum()); cell.setUserValue(undoState.getUserValue()); cell.mPossibles = undoState.getPossibles(); if (undoState.getBatch()) restoreUndo(); } if (undoList.isEmpty()) this.actions[2].setVisibility(View.INVISIBLE); }
public void modifyCell() { GridCell selectedCell = this.kenKenGrid.mSelectedCell; if (!this.kenKenGrid.mActive) return; if (selectedCell == null) return; if (modes[ERASER].isSelected()) { selectedCell.setSelectedCellColor(modeColours[ERASER]); // green if (selectedCell.isUserValueSet() || selectedCell.mPossibles.size() > 0) { saveUndo(selectedCell, false); selectedCell.clearUserValue(); } } else { if (modes[INPUT].isSelected() && lastnum != 0) enterNumber(lastnum); if (modes[PEN].isSelected()) { selectedCell.setSelectedCellColor(modeColours[PEN]); if (selectedCell.mPossibles.size() == 1) { saveUndo(selectedCell, false); selectedCell.setUserValue(selectedCell.mPossibles.get(0)); if (rmpencil) removePossibles(selectedCell); } } else { selectedCell.setSelectedCellColor(modeColours[PENCIL]); if (selectedCell.isUserValueSet()) { saveUndo(selectedCell, false); selectedCell.toggleUserValue(); } } } this.kenKenGrid.requestFocus(); this.kenKenGrid.invalidate(); }
public boolean setSinglePossibles() { ArrayList<GridCell> possibleCells = this.kenKenGrid.getSinglePossibles(); int counter = 0; for (GridCell cell : possibleCells) { // set batch as false for first cell saveUndo(cell, counter++ != 0); cell.setUserValue(cell.mPossibles.get(0)); } this.kenKenGrid.requestFocus(); this.kenKenGrid.invalidate(); return true; }
public void printEntries() { for (int y = 0; y < grid.getHeight(); y++) { System.out.print(y + 1 + ") "); for (int x = 0; x < grid.getWidth(); x++) { GridCell cell = grid.getCell(x, y); String content = cell.getContent(); if (content == null) { content = "*"; } System.out.print(" " + content + " "); } System.out.println(); } }
/** * ************************* Helper functions to modify KenKen grid cells * ************************* */ public void enterNumber(int number) { GridCell selectedCell = this.kenKenGrid.mSelectedCell; if (!this.kenKenGrid.mActive) return; if (selectedCell == null) return; saveUndo(selectedCell, false); if (modes[PEN].isSelected()) { selectedCell.setUserValue(number); if (rmpencil) removePossibles(selectedCell); } else { if (selectedCell.isUserValueSet()) selectedCell.clearUserValue(); selectedCell.togglePossible(number); } this.kenKenGrid.requestFocus(); this.kenKenGrid.invalidate(); }
@Override public View getView(int position, View convertView, ViewGroup parent) { GridCell cell = null; if (null == convertView) { convertView = LayoutInflater.from(mContext).inflate(R.layout.view_category_grid_cell, null); cell = new GridCell(); cell.icon = (NumButton) convertView.findViewById(R.id.category_icon); cell.name = (TextView) convertView.findViewById(R.id.category_name); convertView.setTag(cell); } else { cell = (GridCell) convertView.getTag(); } Category category = DataEngine.getInstance().getCategoryList()[position]; cell.icon.setIconFromUrl(category.getIcon()); cell.icon.setNum(category.getCount()); cell.name.setText(category.getName()); return convertView; }
public void getScreenShot() { // if (!kenKenGrid.mActive) // return; File path = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/Calcudoku/"); if (!path.exists()) path.mkdir(); GridView grid = (GridView) findViewById(R.id.gridview); if (grid.mCells == null) { return; } for (GridCell cell : grid.mCells) cell.mSelected = false; grid.setDrawingCacheEnabled(true); String filename = "/calcudoku_" + grid.mGridSize + "_" + new SimpleDateFormat("yyyyMMdd_HHmm").format(new Date()) + ".png"; // Bitmap bitmap = loadBitmapFromView(grid); Bitmap bitmap = grid.getDrawingCache(); File file = new File(path, filename); try { file.createNewFile(); FileOutputStream ostream = new FileOutputStream(file); bitmap.compress(CompressFormat.PNG, 90, ostream); ostream.flush(); ostream.close(); } catch (Exception e) { e.printStackTrace(); } grid.destroyDrawingCache(); makeToast(getString(R.string.puzzle_screenshot) + path); // Initiate sharing dialog Intent share = new Intent(Intent.ACTION_SEND); share.setType("image/png"); share.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file)); startActivity(Intent.createChooser(share, getString(R.string.menu_share))); }
@Override protected final void updateItem(LocalFile item, boolean empty) { super.updateItem(item, empty); icon.set(null); title.setValue(""); if (!empty) { icon.set(item.getIcon()); title.setValue(item.getFileName()); } }
@Test(dataProvider = "testConstructorPathDataProvider2") public void getPathSelectorCorrectlyFromConstructors2(GridCell gridCell, String expectedXpath) { Assert.assertEquals(gridCell.getXPath(), expectedXpath); }
public void saveUndo(GridCell cell, boolean batch) { UndoState undoState = new UndoState(cell.mCellNumber, cell.getUserValue(), cell.mPossibles, batch); undoList.add(undoState); this.actions[2].setVisibility(View.VISIBLE); }