In the hello android book there is a Sudoku solution. I wanted to create a message at the end that displays a dialog saying congratulations. I have a method to check if there are any empty squareds left and I call that in another method that checks if the last input was a valid entry for the square
/****** Check to see if the game is complete **/
public boolean isSolved() {
for (int element : puzzle) {
if (element == 0)
return false;
}
return true;
}
/** Change the tile only if it's a valid move */
protected boolean setTileIfValid(int x, int y, int value) {
int tiles[] = getUsedTiles(x, y);
if (value != 0) {
for (int tile : tiles) {
if (tile == value)
return false;
}
}
setTile(x, y, value);
calculateUsedTiles();
//check if the game is complete after each valid move
if (isSolved() == true) {
Intent i = new Intent(this, Congratulations.class);
startActivity(i);}
else
{
return false;
}
return true;
}
For some reason when i enter a tile before the game is complete the whole screen shakes from side to side. This did not do this before I entered the checking of the game. Why and where is it doing this?
Congratulatons.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip" >
<TextView
android:id="@+id/about_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/congratulations_text" />
</ScrollView>
Congratulations.java
package com.example.sudoku;
import android.app.Activity;
import android.os.Bundle;
public class Congratulations extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.congratulations);
}
}
Seems like there’s some animation, responsible for shaking the screen.
It might be attached to the Congratulations Activity.
I think you need to search your code (especially the Congratulations Activity) for this method:
Or it could be a theme (also custom theme) responsible for the animation in the activity tag of the AndroidManifest.xml
Maybe it’s not the Congratulations Activity at all. It’s probably the code part which is called, when the Sudoku was not solved yet.