Created
March 28, 2011 17:21
-
-
Save bderusha/890871 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.sudoku; | |
import android.app.Activity; | |
import android.os.Bundle; | |
public class About extends Activity { | |
/** Called when the activity is first created. */ | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.about); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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_title" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/about_text" | |
/> | |
</ScrollView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<array name="difficulty"> | |
<item>@string/easy_label</item> | |
<item>@string/medium_label</item> | |
<item>@string/hard_label</item> | |
</array> | |
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:background="@color/background" | |
android:orientation="horizontal" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:padding="15dip" | |
> | |
<LinearLayout | |
android:orientation="vertical" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:paddingRight="20dip" | |
android:paddingLeft="20dip" | |
> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/main_title" | |
android:layout_gravity="center" | |
android:layout_marginBottom="20dip" | |
android:textSize="24.5sp" | |
/> | |
<TableLayout | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:stretchColumns="*" > | |
<TableRow> | |
<Button | |
android:id="@+id/continue_button" | |
android:text="@string/continue_label" /> | |
<Button | |
android:id="@+id/new_button" | |
android:text="@string/new_game_label" /> | |
</TableRow> | |
<TableRow> | |
<Button | |
android:id="@+id/about_button" | |
android:text="@string/about_label" /> | |
<Button | |
android:id="@+id/exit_button" | |
android:text="@string/exit_label" /> | |
</TableRow> | |
</TableLayout> | |
</LinearLayout> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:background="@color/background" | |
android:orientation="horizontal" | |
android:layout_width="fill_parent" | |
android:layout_height="fill_parent" | |
android:padding="30dip" | |
> | |
<LinearLayout | |
android:orientation="vertical" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="@string/main_title" | |
android:layout_gravity="center" | |
android:layout_marginBottom="25dip" | |
android:textSize="24.5sp" | |
/> | |
<Button | |
android:id="@+id/continue_button" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:text="@string/continue_label" /> | |
<Button | |
android:id="@+id/new_button" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:text="@string/new_game_label" /> | |
<Button | |
android:id="@+id/about_button" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:text="@string/about_label" /> | |
<Button | |
android:id="@+id/exit_button" | |
android:layout_width="fill_parent" | |
android:layout_height="wrap_content" | |
android:text="@string/exit_label" /> | |
</LinearLayout> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.sudoku; | |
import android.os.Bundle; | |
import android.preference.PreferenceActivity; | |
public class Prefs extends PreferenceActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
addPreferencesFromResource(R.xml.settings); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<PreferenceScreen | |
xmlns:android="http://schemas.android.com/apk/res/android"> | |
<CheckBoxPreference | |
android:key="music" | |
android:title="@string/music_title" | |
android:summary="@string/music_summary" | |
android:defaultValue="true" /> | |
<CheckBoxPreference | |
android:key="hints" | |
android:title="@string/hints_title" | |
android:summary="@string/hints_summary" | |
android:defaultValue="true" /> | |
</PreferenceScreen> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<resources> | |
<string name="app_name">Sudoku</string> | |
<string name="main_title">Android Sudoku</string> | |
<string name="about_title">About Android Sudoku</string> | |
<string name="continue_label">Continue</string> | |
<string name="new_game_label">New Game</string> | |
<string name="about_label">About</string> | |
<string name="exit_label">Exit</string> | |
<string name="about_text">\ | |
Sudoku is a logic based number placement puzzle. | |
Starting with a partially completed 9x9 grid, the | |
objective is to fill the grid so that each | |
row, each column, and each of the 3x3 boxes | |
(also called <i>blocks</i>) contains the digits | |
1 to 9 exactly once. | |
</string> | |
<string name="settings_label">Settings...</string> | |
<string name="settings_title">Sudoku settings</string> | |
<string name="settings_shortcut">s</string> | |
<string name="music_title">Music</string> | |
<string name="music_summary">Play background music</string> | |
<string name="hints_title">Hints</string> | |
<string name="hints_summary">Show hints during play</string> | |
<string name="new_game_title">Difficulty</string> | |
<string name="easy_label">Easy</string> | |
<string name="medium_label">Medium</string> | |
<string name="hard_label">Hard</string> | |
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.sudoku; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.content.Intent; | |
import android.view.View; | |
import android.view.View.OnClickListener; | |
import android.view.Menu; | |
import android.view.MenuInflater; | |
import android.view.MenuItem; | |
import android.app.AlertDialog; | |
import android.content.DialogInterface; | |
import android.util.Log; | |
public class Sudoku extends Activity implements OnClickListener{ | |
/** Called when the activity is first created. */ | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.main); | |
//Set up click listeners | |
View continueButton = findViewById(R.id.continue_button); | |
continueButton.setOnClickListener(this); | |
View newButton = findViewById(R.id.new_button); | |
newButton.setOnClickListener(this); | |
View aboutButton = findViewById(R.id.about_button); | |
aboutButton.setOnClickListener(this); | |
View exitButton = findViewById(R.id.exit_button); | |
exitButton.setOnClickListener(this); | |
} | |
public void onClick(View v){ | |
switch (v.getId()) { | |
case R.id.about_button: | |
Intent i = new Intent(this, About.class); | |
startActivity(i); | |
break; | |
case R.id.new_button: | |
openNewGameDialog(); | |
break; | |
case R.id.exit_button: | |
finish(); | |
break; | |
} | |
} | |
private static final String TAG = "Sudoku"; | |
private void openNewGameDialog(){ | |
new AlertDialog.Builder(this) | |
.setTitle(R.string.new_game_title) | |
.setItems(R.array.difficulty, | |
new DialogInterface.OnClickListener() { | |
public void onClick(DialogInterface dialoginterface, | |
int i) { | |
startGame(i); | |
} | |
}) | |
.show(); | |
} | |
//Start a new game | |
private void startGame(int i) { | |
Log.d(TAG, "clicked on " + i); | |
// Start game here... | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu){ | |
super.onCreateOptionsMenu(menu); | |
MenuInflater inflater = getMenuInflater(); | |
inflater.inflate(R.menu.menu, menu); | |
return true; | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
switch (item.getItemId()) { | |
case R.id.settings: | |
startActivity(new Intent(this, Prefs.class)); | |
return true; | |
// More items go here (if any) ... | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment