diff --git a/app/src/main/java/org/vostan/banvor/PuzzleBoardFragment.java b/app/src/main/java/org/vostan/banvor/PuzzleBoardFragment.java index 6ed7d2a..9d7867b 100644 --- a/app/src/main/java/org/vostan/banvor/PuzzleBoardFragment.java +++ b/app/src/main/java/org/vostan/banvor/PuzzleBoardFragment.java @@ -78,10 +78,7 @@ public class PuzzleBoardFragment extends Fragment PuzzleBoardFragment.this.initAndShowCurrentPuzzle(); }); binding.btnUndo.setOnClickListener((View.OnClickListener) v -> { - createNextLevelDialog((d, w) -> { - gameState.advanceCurrentLevel(); - initAndShowCurrentPuzzle(); - }).show(); + binding.gameBoard.undoLastMove(); }); } @@ -99,17 +96,6 @@ public class PuzzleBoardFragment extends Fragment // // Bring a dialog for user to choose to continue or stop. // -// DialogFragment df = new DialogFragment() { -// public Dialog onCreateDialog(Bundle savedInstanceState) { -// return createNextLevelDialog(new DialogInterface.OnClickListener(){ -// public void onClick(DialogInterface d, int w){ -// gameState.advanceCurrentLevel(); -// initAndShowCurrentPuzzle(); -// } -// }); -// } -// }; -// df.show(getChildFragmentManager(), null); createNextLevelDialog((d, w) -> { gameState.advanceCurrentLevel(); initAndShowCurrentPuzzle(); diff --git a/app/src/main/java/org/vostan/banvor/board/PlayActivity.java b/app/src/main/java/org/vostan/banvor/board/PlayActivity.java deleted file mode 100644 index d1180a9..0000000 --- a/app/src/main/java/org/vostan/banvor/board/PlayActivity.java +++ /dev/null @@ -1,211 +0,0 @@ -package org.vostan.banvor.board; - -import android.app.AlertDialog; -import android.app.Dialog; -import android.content.DialogInterface; -import android.os.Bundle; -import androidx.fragment.app.DialogFragment; -import androidx.fragment.app.FragmentActivity; - -import android.util.AttributeSet; -import android.view.View; -import android.view.Window; -import android.view.animation.Animation; -import android.view.animation.AnimationUtils; -import android.widget.FrameLayout; -import android.widget.TextView; - -import org.vostan.banvor.App; - -import static org.vostan.banvor.App.theApp; -import org.vostan.banvor.R; -import org.vostan.banvor.model.Puzzle; - -public class PlayActivity extends FragmentActivity - implements PuzzleControl.PuzzleControlLister -{ - protected final static int RESET_ITEM = 1; - protected final static int UNDO_ITEM = 2; - - public Puzzle puzzle = null; - public PuzzleControl puzzle_view; - View title_view; - public TextView title_text; - - @Override - public void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - // - // No title. - // - requestWindowFeature(Window.FEATURE_NO_TITLE); - // - // Create and set up the puzzle_view. - // -// puzzle_view = new PuzzleControl(this, new AttributeSet() { -// }); - setContentView( puzzle_view ); - puzzle_view.setPuzzleControlLister( this ); - // - // Create action bar. - // - FrameLayout rootLayout = (FrameLayout)findViewById(android.R.id.content); - View.inflate(this, R.layout.fragment_puzzle_board, rootLayout); - title_text = (TextView)findViewById(R.id.level_text); -// title_view = findViewById(R.id.puzzle_view_title_layout); - // - // Load the puzzle. - // - loadCurrentPuzzle(); - } - - public void onSolved() - { - // - // Advance current level and achieved level. - // - final int nextl = theApp().state().getCurrentLevel()+1; -// theApp().state().(nextl); - theApp().state().setCurrentLevel(nextl); - // - // Bring a dialog for user to choose to continue or stop. - // - DialogFragment df = new DialogFragment() - { - public Dialog onCreateDialog(Bundle savedInstanceState) - { - AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder.setTitle("Congratulations! You Won!"); - builder.setMessage( "Would you like to try the next puzzle?" ); - builder.setNegativeButton("Enough", - new DialogInterface.OnClickListener() - { - public void onClick(DialogInterface d, int w) - { - finish(); - } - }); - builder.setPositiveButton("Please", - new DialogInterface.OnClickListener() - { - public void onClick(DialogInterface d, int w) - { - loadCurrentPuzzle(); - puzzle_view.invalidate(); - } - }); - // Create the AlertDialog object and return it - Dialog dlg = builder.create(); - dlg.setCancelable(false); - dlg.setCanceledOnTouchOutside(false); - return dlg; - } - }; - df.setCancelable(false); - df.show(getSupportFragmentManager(), null); - //dlg.show(); - } - - public void onLongPress() - { - if ( title_view.getVisibility() != View.VISIBLE ) - showTitle(); - } - - public void onTouch() - { - if ( title_view.getVisibility() == View.VISIBLE ) - hideTitle(); - } - - public void showTitle() - { - Animation anim = AnimationUtils.loadAnimation(this, R.animator.puzzle_action_bar_enter); - title_view.startAnimation(anim); - title_view.setVisibility(View.VISIBLE); - } - - public void hideTitle() - { - Animation anim = AnimationUtils.loadAnimation(this, R.animator.puzzle_action_bar_exit); - title_view.startAnimation(anim); - title_view.setVisibility(View.INVISIBLE); - } - - public boolean onReset( View v ) - { - while ( puzzle.isUndoable() ) - puzzle.restore(); - puzzle_view.invalidate(); - return true; - } - // - // Go to previouse puzzle. - // - public boolean onPrev( View v ) - { - // - // If current level is less than achived level the move to next - // puzzle. - // - if ( theApp().state().getCurrentLevel() > App.MIN_LEVEL ) - { - theApp().state().setCurrentLevel( theApp().state().getCurrentLevel()-1 ); - loadCurrentPuzzle(); - puzzle_view.invalidate(); - } - return true; - } - // - // Go to next puzzle. - // - public boolean onNext( View v ) - { - // - // If current level is less than achived level the move to next - // puzzle. - // - if ( theApp().state().getCurrentLevel() < theApp().state().getHighestSolvedLevel() ) - { - theApp().state().setCurrentLevel( theApp().state().getCurrentLevel()+1 ); - loadCurrentPuzzle(); - puzzle_view.invalidate(); - - } - return true; - } - // - // Undo last action. - // - public boolean onUndo( View v ) - { - if ( puzzle.isUndoable() ) - { - puzzle.restore(); - puzzle_view.invalidate(); - return true; - } - else - return false; - } - - private void loadCurrentPuzzle() - { - puzzle = theApp().state().getCurrentPuzzle(); - puzzle_view.setPuzzle(puzzle); - updateTitle(); - } - public void updateTitle() - { - String title = "Level " + new Integer(theApp().state().getCurrentLevel()).toString(); - setTitle(title); - } - public void setTitle(CharSequence title) - { - super.setTitle(title); - if (title_text != null) { - title_text.setText(title); - } - } -} diff --git a/app/src/main/java/org/vostan/banvor/board/PuzzleControl.java b/app/src/main/java/org/vostan/banvor/board/PuzzleControl.java index 12c7669..a685d31 100644 --- a/app/src/main/java/org/vostan/banvor/board/PuzzleControl.java +++ b/app/src/main/java/org/vostan/banvor/board/PuzzleControl.java @@ -5,7 +5,6 @@ package org.vostan.banvor.board; import android.content.Context; -import android.graphics.Point; import android.util.AttributeSet; import android.view.GestureDetector; import android.view.MotionEvent; @@ -29,7 +28,7 @@ public class PuzzleControl extends PuzzleView { protected GestureDetector simpled; protected ScaleGestureDetector scaled; - protected PuzzleChoreographer logic; + protected PuzzleChoreographer choregrapher; protected Animator animator; protected PuzzleAnimator puzzleAnimator; protected PuzzleControlLister lister; @@ -47,7 +46,7 @@ public class PuzzleControl extends PuzzleView public PuzzleControl(Context c, AttributeSet attributeSet) { super(c,attributeSet); - logic = new PuzzleChoreographer(); + choregrapher = new PuzzleChoreographer(); animator = new Animator( this ); animator.setAnimationLister(this); puzzleAnimator = new PuzzleAnimator(animator); @@ -60,14 +59,21 @@ public class PuzzleControl extends PuzzleView public void setPuzzle( Puzzle p ) { super.setPuzzle(p); - logic.setPuzzle(p); + choregrapher.setPuzzle(p); } public void setPuzzleControlLister( PuzzleControlLister l ) { lister = l; } - + + public void undoLastMove(){ + if ( getPuzzle().isUndoable() ){ + getPuzzle().restore(); + invalidate(); + } + } + @Override public boolean onTouchEvent(MotionEvent event) { @@ -125,7 +131,7 @@ public class PuzzleControl extends PuzzleView // // Create sequence of steps and then animate it. // - if ( logic.createSteps(puzzleAnimator, singleTapTile)) + if ( choregrapher.createSteps(puzzleAnimator, singleTapTile)) { puzzle.save(); animator.play(); diff --git a/app/src/main/java/org/vostan/banvor/game/IPuzzleSource.java b/app/src/main/java/org/vostan/banvor/game/IPuzzleSource.java new file mode 100644 index 0000000..38b8157 --- /dev/null +++ b/app/src/main/java/org/vostan/banvor/game/IPuzzleSource.java @@ -0,0 +1,8 @@ +package org.vostan.banvor.game; + +import org.vostan.banvor.model.Puzzle; + +public interface IPuzzleSource { + public int getCount(); + public Puzzle getPuzzle(int i ); +} diff --git a/app/src/main/java/org/vostan/banvor/game/PuzzleContainer.java b/app/src/main/java/org/vostan/banvor/game/PuzzleContainer.java index 7445599..f0ea142 100644 --- a/app/src/main/java/org/vostan/banvor/game/PuzzleContainer.java +++ b/app/src/main/java/org/vostan/banvor/game/PuzzleContainer.java @@ -4,10 +4,7 @@ import java.io.InputStream; import static org.vostan.banvor.App.theApp; -import org.vostan.banvor.game.PuzzleBinLoader; - import org.vostan.banvor.R; -import org.vostan.banvor.model.IPuzzleSource; import org.vostan.banvor.model.Puzzle; public class PuzzleContainer implements IPuzzleSource diff --git a/app/src/main/java/org/vostan/banvor/game/State.java b/app/src/main/java/org/vostan/banvor/game/State.java index 3bd3802..10de84c 100644 --- a/app/src/main/java/org/vostan/banvor/game/State.java +++ b/app/src/main/java/org/vostan/banvor/game/State.java @@ -7,7 +7,6 @@ import android.util.Log; import androidx.annotation.NonNull; -import org.vostan.banvor.model.IPuzzleSource; import org.vostan.banvor.model.Puzzle; public class State { diff --git a/app/src/main/java/org/vostan/banvor/model/IPuzzleSource.java b/app/src/main/java/org/vostan/banvor/model/IPuzzleSource.java deleted file mode 100644 index 3016e9a..0000000 --- a/app/src/main/java/org/vostan/banvor/model/IPuzzleSource.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.vostan.banvor.model; - -public interface IPuzzleSource { - public int getCount(); - public Puzzle getPuzzle( int i ); -} diff --git a/app/src/main/res/layout/fragment_puzzle_board.xml b/app/src/main/res/layout/fragment_puzzle_board.xml index cc64f49..a2aa459 100644 --- a/app/src/main/res/layout/fragment_puzzle_board.xml +++ b/app/src/main/res/layout/fragment_puzzle_board.xml @@ -109,7 +109,6 @@ android:background="@color/transparent" android:scaleType="fitCenter" android:src="@drawable/undo" - android:visibility="gone" tools:visibility="visible" />