Added a new game dialog, and game management to GameListActivity
Change-Id: I222b29cc6bcea844b97d13c212e3330336b21a06
This commit is contained in:
36
ExaltedDice/res/layout/new_game_dialog.xml
Normal file
36
ExaltedDice/res/layout/new_game_dialog.xml
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" >
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/linearLayout1"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:layout_centerHorizontal="true" >
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progress"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/editText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="5dip"
|
||||||
|
android:layout_marginRight="5dip"
|
||||||
|
android:hint="@string/game_name"
|
||||||
|
android:singleLine="true" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/new_game_button"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/linearLayout1"
|
||||||
|
android:text="@string/create_new_game" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
||||||
@@ -6,5 +6,9 @@
|
|||||||
<string name="email">twentycodes@gmail.com</string>
|
<string name="email">twentycodes@gmail.com</string>
|
||||||
<string name="deleteing">Deleting…</string>
|
<string name="deleteing">Deleting…</string>
|
||||||
<string name="empty_msg">Click the plus button to start a new game</string>
|
<string name="empty_msg">Click the plus button to start a new game</string>
|
||||||
|
<string name="game_name">Game Name</string>
|
||||||
|
<string name="create_new_game">Create New Game</string>
|
||||||
|
<string name="delete">Delete</string>
|
||||||
|
<string name="new_game">New Game</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
@@ -388,37 +388,37 @@ public class Database {
|
|||||||
* @param gameHistory values
|
* @param gameHistory values
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void insertRinger(String gameName, ContentValues gameHistory){
|
public void insertGame(String gameName, ContentValues gameHistory){
|
||||||
ContentValues game = new ContentValues();
|
ContentValues game = new ContentValues();
|
||||||
game.put(Database.KEY_NAME, checkName(gameName));
|
game.put(Database.KEY_NAME, checkName(gameName));
|
||||||
mDb.insert(GAME_NAME_TABLE, null, game);
|
mDb.insert(GAME_NAME_TABLE, null, game);
|
||||||
String ringerName = game.getAsString(Database.KEY_NAME);
|
|
||||||
|
|
||||||
//insert the information values
|
if(gameHistory != null)
|
||||||
for(Entry<String, Object> item : gameHistory.valueSet()){
|
//insert the information values
|
||||||
ContentValues values = new ContentValues();
|
for(Entry<String, Object> item : gameHistory.valueSet()){
|
||||||
values.put(KEY_NAME, ringerName);
|
ContentValues values = new ContentValues();
|
||||||
values.put(KEY, item.getKey());
|
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.
|
* Try get the value.
|
||||||
*
|
* If there is a class cast exception, try casting to the next object type.
|
||||||
* The following types are tried:
|
*
|
||||||
* String
|
* The following types are tried:
|
||||||
* Integer
|
* String
|
||||||
* Boolean
|
* Integer
|
||||||
*/
|
* Boolean
|
||||||
try {
|
*/
|
||||||
values.put(KEY_VALUE, (String) item.getValue());
|
|
||||||
} catch (ClassCastException e) {
|
|
||||||
try {
|
try {
|
||||||
values.put(KEY_VALUE, (Boolean) item.getValue() ? 1 : 0);
|
values.put(KEY_VALUE, (String) item.getValue());
|
||||||
} catch (ClassCastException e1) {
|
} catch (ClassCastException e) {
|
||||||
values.put(KEY_VALUE, (Integer) item.getValue());
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.app.Activity;
|
|||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -38,9 +39,11 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
private int mCurrentDie;
|
private int mCurrentDie;
|
||||||
private NumberPicker mDPicker;
|
private NumberPicker mDPicker;
|
||||||
private Database mDb;
|
private Database mDb;
|
||||||
|
private String mGameName;
|
||||||
private static final int MENU_QUIT = Menu.FIRST;
|
private static final int MENU_QUIT = Menu.FIRST;
|
||||||
private static final int MENU_CLEAR = Menu.FIRST + 1;
|
private static final int MENU_CLEAR = Menu.FIRST + 1;
|
||||||
private static final String TAG = "ExaltedDice";
|
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" };
|
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();
|
rollDice();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -88,10 +90,15 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
|
Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this));
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
Log.i(TAG, "onCreate()");
|
Log.i(TAG, "onCreate()");
|
||||||
setContentView(R.layout.main);
|
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 = (ListView) findViewById(R.id.list);
|
||||||
listview.setOnItemClickListener(this);
|
listview.setOnItemClickListener(this);
|
||||||
|
|||||||
@@ -10,9 +10,14 @@ import android.app.Activity;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
|
import android.view.Menu;
|
||||||
import android.view.ContextMenu.ContextMenuInfo;
|
import android.view.ContextMenu.ContextMenuInfo;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
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.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
@@ -21,14 +26,30 @@ import android.widget.ListView;
|
|||||||
*
|
*
|
||||||
* @author ricky barrette
|
* @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 ListView mList;
|
||||||
private Database mDb;
|
private Database mDb;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
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);
|
setContentView(R.layout.game_list);
|
||||||
findViewById(R.id.new_game_button).setOnClickListener(this);
|
findViewById(R.id.new_game_button).setOnClickListener(this);
|
||||||
mList = (ListView) findViewById(android.R.id.list);
|
mList = (ListView) findViewById(android.R.id.list);
|
||||||
|
mList.setOnItemClickListener(this);
|
||||||
|
mList.setEmptyView(findViewById(android.R.id.empty));
|
||||||
registerForContextMenu(mList);
|
registerForContextMenu(mList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,9 +75,9 @@ public class GameListActivity extends Activity implements OnClickListener, Datab
|
|||||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
||||||
/*
|
/*
|
||||||
* TODO
|
* TODO
|
||||||
* delete game
|
|
||||||
* rename game
|
* rename game
|
||||||
*/
|
*/
|
||||||
|
menu.add(0, DELETE, Menu.FIRST, R.string.delete);
|
||||||
super.onCreateContextMenu(menu, v, menuInfo);
|
super.onCreateContextMenu(menu, v, menuInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,14 +89,17 @@ public class GameListActivity extends Activity implements OnClickListener, Datab
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDatabaseUpgradeComplete() {
|
public void onDatabaseUpgradeComplete() {
|
||||||
// TODO Auto-generated method stub
|
refresh();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDeletionComplete() {
|
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
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
mDb = new Database(this, this);
|
mDb = new Database(this, this);
|
||||||
mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mDb.getAllGameTitles()));
|
refresh();
|
||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void refresh() {
|
||||||
|
mList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mDb.getAllGameTitles()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user