diff --git a/ExaltedDice/res/layout/new_game_dialog.xml b/ExaltedDice/res/layout/new_game_dialog.xml
new file mode 100644
index 0000000..a0e71c0
--- /dev/null
+++ b/ExaltedDice/res/layout/new_game_dialog.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ExaltedDice/res/values/strings.xml b/ExaltedDice/res/values/strings.xml
index b825912..261ffc7 100755
--- a/ExaltedDice/res/values/strings.xml
+++ b/ExaltedDice/res/values/strings.xml
@@ -6,5 +6,9 @@
twentycodes@gmail.com
Deleting…
Click the plus button to start a new game
+ Game Name
+ Create New Game
+ Delete
+ New Game
\ No newline at end of file
diff --git a/ExaltedDice/src/com/TwentyCode/android/ExaltedDice/Database.java b/ExaltedDice/src/com/TwentyCode/android/ExaltedDice/Database.java
index 0fe1fd5..61f5a04 100644
--- a/ExaltedDice/src/com/TwentyCode/android/ExaltedDice/Database.java
+++ b/ExaltedDice/src/com/TwentyCode/android/ExaltedDice/Database.java
@@ -388,37 +388,37 @@ public class Database {
* @param gameHistory values
* @author ricky barrette
*/
- public void insertRinger(String gameName, ContentValues gameHistory){
+ public void insertGame(String gameName, ContentValues gameHistory){
ContentValues game = new ContentValues();
game.put(Database.KEY_NAME, checkName(gameName));
mDb.insert(GAME_NAME_TABLE, null, game);
- String ringerName = game.getAsString(Database.KEY_NAME);
- //insert the information values
- for(Entry item : gameHistory.valueSet()){
- ContentValues values = new ContentValues();
- values.put(KEY_NAME, ringerName);
- values.put(KEY, item.getKey());
- /*
- * Try get the value.
- * If there is a class cast exception, try casting to the next object type.
- *
- * The following types are tried:
- * String
- * Integer
- * Boolean
- */
- try {
- values.put(KEY_VALUE, (String) item.getValue());
- } catch (ClassCastException e) {
+ if(gameHistory != null)
+ //insert the information values
+ for(Entry item : gameHistory.valueSet()){
+ ContentValues values = new ContentValues();
+ values.put(KEY_NAME, gameName);
+ values.put(KEY, item.getKey());
+ /*
+ * Try get the value.
+ * If there is a class cast exception, try casting to the next object type.
+ *
+ * The following types are tried:
+ * String
+ * Integer
+ * Boolean
+ */
try {
- values.put(KEY_VALUE, (Boolean) item.getValue() ? 1 : 0);
- } catch (ClassCastException e1) {
- values.put(KEY_VALUE, (Integer) item.getValue());
+ values.put(KEY_VALUE, (String) item.getValue());
+ } catch (ClassCastException e) {
+ try {
+ values.put(KEY_VALUE, (Boolean) item.getValue() ? 1 : 0);
+ } catch (ClassCastException e1) {
+ values.put(KEY_VALUE, (Integer) item.getValue());
+ }
}
+ mDb.insert(GAME_HISTORY_TABLE, null, values);
}
- mDb.insert(GAME_HISTORY_TABLE, null, values);
- }
}
/**
diff --git a/ExaltedDice/src/com/TwentyCode/android/ExaltedDice/ExaltedDice.java b/ExaltedDice/src/com/TwentyCode/android/ExaltedDice/ExaltedDice.java
index a18169d..57faa41 100755
--- a/ExaltedDice/src/com/TwentyCode/android/ExaltedDice/ExaltedDice.java
+++ b/ExaltedDice/src/com/TwentyCode/android/ExaltedDice/ExaltedDice.java
@@ -7,6 +7,7 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.Intent;
import android.os.Bundle;
import android.os.Vibrator;
import android.util.Log;
@@ -38,9 +39,11 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
private int mCurrentDie;
private NumberPicker mDPicker;
private Database mDb;
+ private String mGameName;
private static final int MENU_QUIT = Menu.FIRST;
private static final int MENU_CLEAR = Menu.FIRST + 1;
private static final String TAG = "ExaltedDice";
+ public static final String KEY_GAME_NAME = "game_name";
private static final String[] DICE_VALUES = { "D2", "D3", "D4", "D6", "D8", "D10", "D12", "D20", "D100" };
/**
@@ -67,7 +70,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
rollDice();
break;
}
-
}
/**
@@ -88,10 +90,15 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
@Override
public void onCreate(Bundle savedInstanceState) {
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
-
super.onCreate(savedInstanceState);
Log.i(TAG, "onCreate()");
setContentView(R.layout.main);
+ Intent i = this.getIntent();
+ if(i != null)
+ if(i.hasExtra(KEY_GAME_NAME)){
+ mGameName = i.getStringExtra(KEY_GAME_NAME);
+ this.setTitle(mGameName);
+ }
listview = (ListView) findViewById(R.id.list);
listview.setOnItemClickListener(this);
diff --git a/ExaltedDice/src/com/TwentyCode/android/ExaltedDice/GameListActivity.java b/ExaltedDice/src/com/TwentyCode/android/ExaltedDice/GameListActivity.java
index e643d4d..e5c0225 100644
--- a/ExaltedDice/src/com/TwentyCode/android/ExaltedDice/GameListActivity.java
+++ b/ExaltedDice/src/com/TwentyCode/android/ExaltedDice/GameListActivity.java
@@ -10,9 +10,14 @@ import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
+import android.view.Menu;
import android.view.ContextMenu.ContextMenuInfo;
+import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
+import android.widget.AdapterView;
+import android.widget.AdapterView.AdapterContextMenuInfo;
+import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
@@ -21,14 +26,30 @@ import android.widget.ListView;
*
* @author ricky barrette
*/
-public class GameListActivity extends Activity implements OnClickListener, DatabaseListener {
+public class GameListActivity extends Activity implements OnClickListener, DatabaseListener, OnItemClickListener {
+ private static final int DELETE = 0;
private ListView mList;
private Database mDb;
@Override
public void onClick(View v) {
- startActivity(new Intent(this, ExaltedDice.class));
+ new NewGameDialog(this, mDb).show();
+ }
+
+ /**
+ * (non-Javadoc)
+ * @see android.app.Activity#onContextItemSelected(android.view.MenuItem)
+ */
+ @Override
+ public boolean onContextItemSelected(MenuItem item) {
+ AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
+ switch(item.getItemId()){
+ case DELETE:
+ mDb.deleteGame(info.id+1);
+ break;
+ }
+ return super.onContextItemSelected(item);
}
/**
@@ -41,6 +62,8 @@ public class GameListActivity extends Activity implements OnClickListener, Datab
setContentView(R.layout.game_list);
findViewById(R.id.new_game_button).setOnClickListener(this);
mList = (ListView) findViewById(android.R.id.list);
+ mList.setOnItemClickListener(this);
+ mList.setEmptyView(findViewById(android.R.id.empty));
registerForContextMenu(mList);
}
@@ -52,9 +75,9 @@ public class GameListActivity extends Activity implements OnClickListener, Datab
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
/*
* TODO
- * delete game
* rename game
*/
+ menu.add(0, DELETE, Menu.FIRST, R.string.delete);
super.onCreateContextMenu(menu, v, menuInfo);
}
@@ -66,14 +89,17 @@ public class GameListActivity extends Activity implements OnClickListener, Datab
@Override
public void onDatabaseUpgradeComplete() {
- // TODO Auto-generated method stub
-
+ refresh();
}
@Override
public void onDeletionComplete() {
- // TODO Auto-generated method stub
-
+ refresh();
+ }
+
+ @Override
+ public void onItemClick(AdapterView> parent, View view, int position, long id) {
+ startActivity(new Intent(this, ExaltedDice.class).putExtra(ExaltedDice.KEY_GAME_NAME, mDb.getGameName(id +1)));
}
/**
@@ -99,8 +125,12 @@ public class GameListActivity extends Activity implements OnClickListener, Datab
@Override
protected void onResume() {
mDb = new Database(this, this);
- mList.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, mDb.getAllGameTitles()));
+ refresh();
super.onResume();
}
+ private void refresh() {
+ mList.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, mDb.getAllGameTitles()));
+ }
+
}
diff --git a/ExaltedDice/src/com/TwentyCode/android/ExaltedDice/NewGameDialog.java b/ExaltedDice/src/com/TwentyCode/android/ExaltedDice/NewGameDialog.java
new file mode 100644
index 0000000..f1594f2
--- /dev/null
+++ b/ExaltedDice/src/com/TwentyCode/android/ExaltedDice/NewGameDialog.java
@@ -0,0 +1,46 @@
+/**
+ * NewGameDialog.java
+ * @date Feb 4, 2012
+ * @author ricky barrette
+ * @author Twenty Codes, LLC
+ */
+package com.TwentyCode.android.ExaltedDice;
+
+import android.app.Dialog;
+import android.content.Context;
+import android.content.Intent;
+import android.view.View;
+import android.widget.EditText;
+
+/**
+ * This dialog will be used to allow a user to enter a name for their game
+ * @author ricky barrette
+ */
+public class NewGameDialog extends Dialog implements android.view.View.OnClickListener {
+
+ private Context mContext;
+ private Database mDb;
+ private EditText mGameName;
+
+ public NewGameDialog(Context context, Database db) {
+ super(context);
+ mContext = context;
+ mDb = db;
+ this.setTitle(R.string.new_game);
+ this.setContentView(R.layout.new_game_dialog);
+ findViewById(R.id.new_game_button).setOnClickListener(this);
+ mGameName = (EditText) findViewById(R.id.editText);
+ }
+
+ @Override
+ public void onClick(View v) {
+ findViewById(R.id.progress).setVisibility(View.VISIBLE);
+ findViewById(R.id.new_game_button).setEnabled(false);
+
+ String name = mGameName.getText().toString();
+ mDb.insertGame(name, null);
+ mContext.startActivity(new Intent(mContext, ExaltedDice.class).putExtra(ExaltedDice.KEY_GAME_NAME, name));
+ this.dismiss();
+ }
+
+}