Add a FinalizeDialogFragment using the CreateSudokuActivity as an IFinalizeDialogFragmentListener to the CreateSudokuSpecialButtonLayout class. The DialogFragment is called when the user clicks on the 'finalize' button.
This commit is contained in:
parent
3bbb6576f9
commit
e420b1b558
2 changed files with 23 additions and 15 deletions
|
@ -25,6 +25,8 @@ import org.secuso.privacyfriendlysudoku.ui.view.SudokuFieldLayout;
|
||||||
import org.secuso.privacyfriendlysudoku.ui.view.SudokuKeyboardLayout;
|
import org.secuso.privacyfriendlysudoku.ui.view.SudokuKeyboardLayout;
|
||||||
import org.secuso.privacyfriendlysudoku.ui.view.SudokuSpecialButtonLayout;
|
import org.secuso.privacyfriendlysudoku.ui.view.SudokuSpecialButtonLayout;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
public class CreateSudokuActivity extends BaseActivity implements IFinalizeDialogFragmentListener {
|
public class CreateSudokuActivity extends BaseActivity implements IFinalizeDialogFragmentListener {
|
||||||
|
|
||||||
GameController gameController;
|
GameController gameController;
|
||||||
|
@ -78,7 +80,7 @@ public class CreateSudokuActivity extends BaseActivity implements IFinalizeDialo
|
||||||
keyboard.setKeyBoard(gameController.getSize(), p.x,layout.getHeight()-p.y, orientation);
|
keyboard.setKeyBoard(gameController.getSize(), p.x,layout.getHeight()-p.y, orientation);
|
||||||
|
|
||||||
CreateSudokuSpecialButtonLayout createSudokuSpecialButtonLayout = (CreateSudokuSpecialButtonLayout) findViewById(R.id.createSudokuLayout);
|
CreateSudokuSpecialButtonLayout createSudokuSpecialButtonLayout = (CreateSudokuSpecialButtonLayout) findViewById(R.id.createSudokuLayout);
|
||||||
createSudokuSpecialButtonLayout.setButtons(p.x, gameController, keyboard, getFragmentManager(), orientation, CreateSudokuActivity.this);
|
createSudokuSpecialButtonLayout.setButtons(p.x, gameController, keyboard, getFragmentManager(), orientation, CreateSudokuActivity.this, this);
|
||||||
|
|
||||||
gameController.notifyHighlightChangedListeners();
|
gameController.notifyHighlightChangedListeners();
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import androidx.core.content.ContextCompat;
|
||||||
import org.secuso.privacyfriendlysudoku.controller.GameController;
|
import org.secuso.privacyfriendlysudoku.controller.GameController;
|
||||||
import org.secuso.privacyfriendlysudoku.game.listener.IHighlightChangedListener;
|
import org.secuso.privacyfriendlysudoku.game.listener.IHighlightChangedListener;
|
||||||
import org.secuso.privacyfriendlysudoku.ui.GameActivity;
|
import org.secuso.privacyfriendlysudoku.ui.GameActivity;
|
||||||
|
import org.secuso.privacyfriendlysudoku.ui.listener.IFinalizeDialogFragmentListener;
|
||||||
import org.secuso.privacyfriendlysudoku.ui.listener.IHintDialogFragmentListener;
|
import org.secuso.privacyfriendlysudoku.ui.listener.IHintDialogFragmentListener;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
@ -31,12 +32,9 @@ import java.util.LinkedList;
|
||||||
import static org.secuso.privacyfriendlysudoku.ui.view.CreateSudokuButtonType.Spacer;
|
import static org.secuso.privacyfriendlysudoku.ui.view.CreateSudokuButtonType.Spacer;
|
||||||
import static org.secuso.privacyfriendlysudoku.ui.view.CreateSudokuButtonType.getSpecialButtons;
|
import static org.secuso.privacyfriendlysudoku.ui.view.CreateSudokuButtonType.getSpecialButtons;
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by TMZ_LToP on 17.11.2015.
|
|
||||||
*/
|
|
||||||
public class CreateSudokuSpecialButtonLayout extends LinearLayout implements IHighlightChangedListener {
|
public class CreateSudokuSpecialButtonLayout extends LinearLayout implements IHighlightChangedListener {
|
||||||
|
|
||||||
|
IFinalizeDialogFragmentListener finalizeDialogFragmentListener;
|
||||||
CreateSudokuSpecialButton[] fixedButtons;
|
CreateSudokuSpecialButton[] fixedButtons;
|
||||||
public int fixedButtonsCount = getSpecialButtons().size();
|
public int fixedButtonsCount = getSpecialButtons().size();
|
||||||
GameController gameController;
|
GameController gameController;
|
||||||
|
@ -72,6 +70,9 @@ public class CreateSudokuSpecialButtonLayout extends LinearLayout implements IHi
|
||||||
gameController.UnDo();
|
gameController.UnDo();
|
||||||
break;
|
break;
|
||||||
case Finalize:
|
case Finalize:
|
||||||
|
FinalizeConfirmationDialog dialog = new FinalizeConfirmationDialog();
|
||||||
|
dialog.addListener(finalizeDialogFragmentListener);
|
||||||
|
dialog.show(fragmentManager, "FinalizeDialogFragment");
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -92,11 +93,13 @@ public class CreateSudokuSpecialButtonLayout extends LinearLayout implements IHi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setButtons(int width, GameController gc, SudokuKeyboardLayout key, FragmentManager fm, int orientation, Context cxt) {
|
public void setButtons(int width, GameController gc, SudokuKeyboardLayout key, FragmentManager fm,
|
||||||
|
int orientation, Context cxt, IFinalizeDialogFragmentListener finalizeListener) {
|
||||||
fragmentManager = fm;
|
fragmentManager = fm;
|
||||||
keyboard=key;
|
keyboard=key;
|
||||||
gameController = gc;
|
gameController = gc;
|
||||||
context = cxt;
|
context = cxt;
|
||||||
|
finalizeDialogFragmentListener = finalizeListener;
|
||||||
if(gameController != null) {
|
if(gameController != null) {
|
||||||
gameController.registerHighlightChangedListener(this);
|
gameController.registerHighlightChangedListener(this);
|
||||||
}
|
}
|
||||||
|
@ -186,29 +189,33 @@ public class CreateSudokuSpecialButtonLayout extends LinearLayout implements IHi
|
||||||
|
|
||||||
canvas = new Canvas(bitResult);
|
canvas = new Canvas(bitResult);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
public static class HintConfirmationDialog extends DialogFragment {
|
|
||||||
|
|
||||||
LinkedList<IHintDialogFragmentListener> listeners = new LinkedList<>();
|
public static class FinalizeConfirmationDialog extends DialogFragment {
|
||||||
|
|
||||||
|
LinkedList<IFinalizeDialogFragmentListener> listeners = new LinkedList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
// Verify that the host activity implements the callback interface
|
// Verify that the host activity implements the callback interface
|
||||||
if(activity instanceof IHintDialogFragmentListener) {
|
if(activity instanceof IFinalizeDialogFragmentListener) {
|
||||||
listeners.add((IHintDialogFragmentListener) activity);
|
listeners.add((IFinalizeDialogFragmentListener) activity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addListener(IFinalizeDialogFragmentListener listener) {
|
||||||
|
listeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
// Use the Builder class for convenient dialog construction
|
// Use the Builder class for convenient dialog construction
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppTheme_Dialog);
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppTheme_Dialog);
|
||||||
builder.setMessage(R.string.hint_confirmation)
|
builder.setMessage("Do you wish to finalize this sudoku?")
|
||||||
.setPositiveButton(R.string.hint_confirmation_confirm, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.hint_confirmation_confirm, new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
for(IHintDialogFragmentListener l : listeners) {
|
for(IFinalizeDialogFragmentListener l : listeners) {
|
||||||
l.onHintDialogPositiveClick();
|
l.onFinalizeDialogPositiveClick();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -220,5 +227,4 @@ public class CreateSudokuSpecialButtonLayout extends LinearLayout implements IHi
|
||||||
return builder.create();
|
return builder.create();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue