Fixed clear history
Fixed the clear history menu item to clear the game's history from the database. rolls generator to ref the number pickers, this fixed the rotation bugs. added roll totals to roll logs update git to ignore bin and gen folders Change-Id: I6b3659cf06e00e38b2939f0ed3d1bd7d4f84e790 Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
2
ExaltedDice/.gitignore
vendored
Normal file
2
ExaltedDice/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
/bin
|
||||||
|
/gen
|
||||||
@@ -226,6 +226,49 @@ public class Database {
|
|||||||
return ringerName;
|
return ringerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the history of a game by it's id
|
||||||
|
* @param gameId
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public void clearHistory(final long gameId) {
|
||||||
|
final ProgressDialog progress = ProgressDialog.show(Database.this.mContext, "", Database.this.mContext.getText(R.string.deleteing), true, true);
|
||||||
|
|
||||||
|
final Handler handler = new Handler(){
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
if(Database.this.mListener != null)
|
||||||
|
Database.this.mListener.onDeletionComplete();
|
||||||
|
progress.dismiss();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//game deleting thread
|
||||||
|
new Thread( new Runnable(){
|
||||||
|
@Override
|
||||||
|
public void run(){
|
||||||
|
Looper.prepare();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* get the game name from the id, and then delete all its information from the game history table
|
||||||
|
*/
|
||||||
|
Database.this.mDb.delete(GAME_HISTORY_TABLE, KEY_NAME +" = "+ DatabaseUtils.sqlEscapeString(getGameName(gameId)), null);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* update the game table
|
||||||
|
*/
|
||||||
|
ContentValues game= new ContentValues();
|
||||||
|
|
||||||
|
//store the current roll
|
||||||
|
game.put(KEY_ROLL_ID, 0);
|
||||||
|
mDb.update(GAME_NAME_TABLE, game, "id" + "= "+ gameId, null);
|
||||||
|
|
||||||
|
|
||||||
|
handler.sendEmptyMessage(0);
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the database
|
* Closes the database
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
|
|||||||
@@ -22,17 +22,14 @@ import android.widget.AdapterView.OnItemClickListener;
|
|||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.NumberPicker;
|
import android.widget.NumberPicker;
|
||||||
import android.widget.NumberPicker.OnValueChangeListener;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.TwentyCodes.android.exception.ExceptionHandler;
|
import com.TwentyCodes.android.exception.ExceptionHandler;
|
||||||
|
|
||||||
public class ExaltedDice extends Activity implements OnClickListener, OnItemClickListener, OnValueChangeListener {
|
public class ExaltedDice extends Activity implements OnClickListener, OnItemClickListener {
|
||||||
|
|
||||||
private ListView mListView;
|
private ListView mListView;
|
||||||
private int intSuccesses;
|
private int intSuccesses;
|
||||||
private int mRolls = 1;
|
|
||||||
private int mD = 2;
|
|
||||||
private NumberPicker mNumberPicker;
|
private NumberPicker mNumberPicker;
|
||||||
private NumberPicker mDPicker;
|
private NumberPicker mDPicker;
|
||||||
private Database mDb;
|
private Database mDb;
|
||||||
@@ -49,11 +46,10 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* clears the rollHistory List array and refreshes the listview
|
* clears the rollHistory List array and refreshes the listview
|
||||||
*
|
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
private void clearHistory() {
|
private void clearHistory() {
|
||||||
//TODO clear history
|
mDb.clearHistory(mGameId);
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,18 +103,17 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
|
|
||||||
mListView = (ListView) findViewById(R.id.list);
|
mListView = (ListView) findViewById(R.id.list);
|
||||||
mListView.setOnItemClickListener(this);
|
mListView.setOnItemClickListener(this);
|
||||||
|
mListView.setStackFromBottom(true);
|
||||||
|
|
||||||
mDPicker = (NumberPicker) findViewById(R.id.d_Picker);
|
mDPicker = (NumberPicker) findViewById(R.id.d_Picker);
|
||||||
mDPicker.setMinValue(0);
|
mDPicker.setMinValue(0);
|
||||||
mDPicker.setMaxValue(DICE_VALUES.length -1);
|
mDPicker.setMaxValue(DICE_VALUES.length -1);
|
||||||
mDPicker.setDisplayedValues(DICE_VALUES);
|
mDPicker.setDisplayedValues(DICE_VALUES);
|
||||||
mDPicker.setOnValueChangedListener(this);
|
|
||||||
mDPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
|
mDPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
|
||||||
|
|
||||||
mNumberPicker = (NumberPicker) findViewById(R.id.number_Picker);
|
mNumberPicker = (NumberPicker) findViewById(R.id.number_Picker);
|
||||||
mNumberPicker.setMaxValue(999);
|
mNumberPicker.setMaxValue(999);
|
||||||
mNumberPicker.setMinValue(1);
|
mNumberPicker.setMinValue(1);
|
||||||
mNumberPicker.setOnValueChangedListener(this);
|
|
||||||
mNumberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
|
mNumberPicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
|
||||||
|
|
||||||
findViewById(R.id.roll_button).setOnClickListener(this);
|
findViewById(R.id.roll_button).setOnClickListener(this);
|
||||||
@@ -126,7 +121,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
/*
|
/*
|
||||||
* display hello message
|
* display hello message
|
||||||
*/
|
*/
|
||||||
mListView.setAdapter(new ArrayAdapter<String>(this, R.layout.list_row, getResources().getStringArray(R.array.hello_msg)));
|
mListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.hello_msg)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -209,8 +204,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
this.setTitle(mDb.getGameName(mGameId));
|
|
||||||
|
|
||||||
if(mDb.getGameRollCount(mGameId) > 0){
|
if(mDb.getGameRollCount(mGameId) > 0){
|
||||||
isNewGame = false;
|
isNewGame = false;
|
||||||
refresh();
|
refresh();
|
||||||
@@ -242,18 +235,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
super.onSaveInstanceState(savedInstanceState);
|
super.onSaveInstanceState(savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
|
|
||||||
switch(picker.getId()){
|
|
||||||
case R.id.d_Picker:
|
|
||||||
mD = Integer.parseInt(DICE_VALUES[newVal].substring(1));
|
|
||||||
break;
|
|
||||||
case R.id.number_Picker:
|
|
||||||
mRolls = newVal;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* displays a quit dialog
|
* displays a quit dialog
|
||||||
*
|
*
|
||||||
@@ -278,8 +259,10 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void refresh(){
|
public void refresh(){
|
||||||
if(!isNewGame)
|
if(!isNewGame){
|
||||||
mListView.setAdapter(mListAdapter);
|
mListView.setAdapter(mListAdapter);
|
||||||
|
isNewGame = false;
|
||||||
|
}
|
||||||
mListAdapter.notifyDataSetChanged();
|
mListAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,25 +276,19 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
public String results(int times) {
|
public String results(int times) {
|
||||||
Log.i(TAG, "results()");
|
Log.i(TAG, "results()");
|
||||||
StringBuffer resultsString = new StringBuffer();
|
StringBuffer resultsString = new StringBuffer();
|
||||||
|
StringBuffer rolls = new StringBuffer();
|
||||||
/**
|
long total = 0;
|
||||||
* roll the dice
|
|
||||||
*/
|
|
||||||
int[] roll = rollGen(times);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* add number of successes to resultsString
|
|
||||||
*/
|
|
||||||
resultsString.append("\nSuccesses: "+ successes(roll) +"\n");
|
|
||||||
|
|
||||||
resultsString.append("Rolled: ");
|
int[] roll = rollGen(times);
|
||||||
/**
|
|
||||||
* add rolled dice results to resultsString
|
for (int item : roll) {
|
||||||
*/
|
rolls.append(item + ", ");
|
||||||
for (int i = 0; i < roll.length; i++) {
|
total = total + item;
|
||||||
resultsString.append(roll[i] + ", ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resultsString.append("Total: "+ total);
|
||||||
|
resultsString.append("\nSuccesses: "+ successes(roll));
|
||||||
|
resultsString.append("\nRolls: "+ rolls.toString());
|
||||||
return resultsString.toString();
|
return resultsString.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,7 +306,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
ContentValues roll = new ContentValues();
|
ContentValues roll = new ContentValues();
|
||||||
roll.put(Database.KEY_D_TYPE, DICE_VALUES[mDPicker.getValue()]);
|
roll.put(Database.KEY_D_TYPE, DICE_VALUES[mDPicker.getValue()]);
|
||||||
roll.put(Database.KEY_NUMBER, mNumberPicker.getValue());
|
roll.put(Database.KEY_NUMBER, mNumberPicker.getValue());
|
||||||
roll.put(Database.KEY_LOG, results(mRolls));
|
roll.put(Database.KEY_LOG, results(mNumberPicker.getValue()));
|
||||||
|
|
||||||
mDb.updateGame(mGameId, mGameName, roll, rollId);
|
mDb.updateGame(mGameId, mGameName, roll, rollId);
|
||||||
|
|
||||||
@@ -337,8 +314,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generates an array containing 10 sided dice rolls
|
* generates an array containing dice rolls
|
||||||
*
|
|
||||||
* @param int times
|
* @param int times
|
||||||
* @return int[] roll
|
* @return int[] roll
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
@@ -348,7 +324,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
int[] roll = new int[times];
|
int[] roll = new int[times];
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
for (int i = 0; i < times; i++) {
|
for (int i = 0; i < times; i++) {
|
||||||
roll[i] = random.nextInt(mD) + 1;
|
roll[i] = random.nextInt(Integer.parseInt(DICE_VALUES[mDPicker.getValue()].substring(1))) + 1;
|
||||||
}
|
}
|
||||||
return roll;
|
return roll;
|
||||||
}
|
}
|
||||||
@@ -387,21 +363,13 @@ public class ExaltedDice extends Activity implements OnClickListener, OnItemClic
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* starts Vibrator service and then vibrates for x milliseconds
|
* starts Vibrator service and then vibrates for x milliseconds
|
||||||
*
|
|
||||||
* @param Long
|
* @param Long
|
||||||
* milliseconds
|
* milliseconds
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void vibrate(long milliseconds) {
|
public void vibrate(long milliseconds) {
|
||||||
Log.i(TAG, "vibrate() for " + milliseconds);
|
Log.i(TAG, "vibrate() for " + milliseconds);
|
||||||
/**
|
|
||||||
* start vibrator service
|
|
||||||
*/
|
|
||||||
Vibrator vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
Vibrator vib = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
|
|
||||||
/**
|
|
||||||
* Vibrate for x milliseconds
|
|
||||||
*/
|
|
||||||
vib.vibrate(milliseconds);
|
vib.vibrate(milliseconds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user