private void createSmallBoxes() { final ViewGroup grid1 = (ViewGroup) findViewById(R.id.gridLayout1); DisplayMetrics displayMetrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); int screenWidth = displayMetrics.widthPixels; int screenHeight = displayMetrics.heightPixels; int divisor = 10; int screenSmallest; if (screenWidth < screenHeight) { screenSmallest = screenWidth; divisor = 10; } else { screenSmallest = screenHeight; divisor = 12; } int cellSize = screenSmallest / divisor; View.OnClickListener listener1 = getSmallBoxOnClickListener(); View.OnLongClickListener listener2 = getSmallBoxOnLongClickListener(); // creating small boxes for (int row = 0; row < 9; row++) { for (int col = 0; col < 9; col++) { SmallBox box1 = new SmallBox(this, this.stateInfo, puzWithSol.puzzle[row][col], row, col, cellSize); box1.setOnClickListener(listener1); box1.setOnLongClickListener(listener2); grid1.addView(box1); box1.setId(row * 9 + col); } } }
public void smallBoxLongClicked(View v) { SmallBox sb2 = (SmallBox) v; SmallBox sb1 = stateInfo.selectedSmallBox; boolean hadSelectedSmallBox = stateInfo.hasSelectedSmallBox; stateInfo.selectedSmallBox = sb2; stateInfo.hasSelectedSmallBox = true; stateInfo.selectingState = StateInfo.SELECTING_POSSIBLE_VALUE; if (hadSelectedSmallBox) sb1.invalidate(); sb2.invalidate(); refreshDigitButtons(); }
void saveInstanceState(Bundle bundle) { bundle.putBoolean("hasSelectedSmallBox", hasSelectedSmallBox); bundle.putInt("selectingState", selectingState); // bundle.putInt("selectedSmallBox_row", selectedSmallBox.cell1.row); // bundle.putInt("selectedSmallBox_col", selectedSmallBox.cell1.col); if (hasSelectedSmallBox) bundle.putInt("selectedSmallBox_ID", selectedSmallBox.getId()); }
public void smallBoxClicked(View v) { SmallBox sb2 = (SmallBox) v; SmallBox sb1 = stateInfo.selectedSmallBox; /* * set has selected to true * set the selected box * set setting final value to true * invalidate the small box and the previously selected small box * invalidate the digitbuttons */ boolean hadSelectedSmallBox = stateInfo.hasSelectedSmallBox; stateInfo.selectedSmallBox = sb2; stateInfo.hasSelectedSmallBox = true; stateInfo.selectingState = StateInfo.SELECTING_FINAL_VALUE; if (hadSelectedSmallBox) sb1.invalidate(); sb2.invalidate(); refreshDigitButtons(); }