Exalted Dice Change Log
0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 V6 -remodeled onClickListeners -remodeled onLongClickListeners 0.0.7 V7 -Got Listview working with 10 item history -removed old onClickListener methods -removed old onLongClickListeners -ads working with internet permisions -Menu with exit option 0.0.8 v8 -cleaned code for efficency -Fixed error checking method to check for a string containing no ints. -Fixed shake listener problem -First release version, full, and ad free -due to a G Market problem, package name switched from com.TwentyCodes.android.ExaltedDice to com.TwentyCode.android.ExaltedDice 0.0.9 V9 -compiled under 1.5 -updated ads -added System.gc(); -added stringbuffer to checkForErrors() and results() -added a dynamic rollHistory list array -added clear history menu option 0.0.10 -added rotaion methods -reformated the output string -added crash report -added roll again feature 1.0.0 i created NumberPickerButton.java. it is completely based on NumberPickerButton.java from the android source. it exist purely to cancel long clicks. ExaltedDice.java i have removed my old privative methods for incrementing / decrementing the dice and replaced it with the method from NumberPicker.java from the android source. i also removed all unused methods i incremented the version / build number from 0.0.10b10 to 1.0.0b11
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.TwentyCode.android.ExaltedDice"
|
package="com.TwentyCode.android.ExaltedDice"
|
||||||
android:versionName="0.0.10" android:versionCode="10">
|
android:versionCode="11" android:versionName="1.0.0">
|
||||||
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
<application android:icon="@drawable/icon" android:label="@string/app_name">
|
||||||
<activity android:name=".ExaltedDice"
|
<activity android:name=".ExaltedDice"
|
||||||
|
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
Exalted Dice Change Log
|
|
||||||
|
|
||||||
0.0.1
|
|
||||||
0.0.2
|
|
||||||
0.0.3
|
|
||||||
0.0.4
|
|
||||||
0.0.5
|
|
||||||
|
|
||||||
0.0.6 V6
|
|
||||||
-remodeled onClickListeners
|
|
||||||
-remodeled onLongClickListeners
|
|
||||||
|
|
||||||
0.0.7 V7
|
|
||||||
-Got Listview working with 10 item history
|
|
||||||
-removed old onClickListener methods
|
|
||||||
-removed old onLongClickListeners
|
|
||||||
-ads working with internet permisions
|
|
||||||
-Menu with exit option
|
|
||||||
|
|
||||||
0.0.8 v8
|
|
||||||
-cleaned code for efficency
|
|
||||||
-Fixed error checking method to check for a string containing no ints.
|
|
||||||
-Fixed shake listener problem
|
|
||||||
-First release version, full, and ad free
|
|
||||||
-due to a G Market problem, package name switched from com.TwentyCodes.android.ExaltedDice to com.TwentyCode.android.ExaltedDice
|
|
||||||
|
|
||||||
|
|
||||||
0.0.9 V9
|
|
||||||
-compiled under 1.5
|
|
||||||
-updated ads
|
|
||||||
-added System.gc();
|
|
||||||
-added stringbuffer to checkForErrors() and results()
|
|
||||||
-added a dynamic rollHistory list array
|
|
||||||
-added clear history menu option
|
|
||||||
|
|
||||||
0.0.10
|
|
||||||
-added rotaion methods
|
|
||||||
-reformated the output string
|
|
||||||
-added crash report
|
|
||||||
-added roll again feature
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -11,7 +11,7 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<Button android:id="@+id/down"
|
<com.TwentyCode.android.ExaltedDice.NumberPickerButton android:id="@+id/down"
|
||||||
android:layout_width="60px"
|
android:layout_width="60px"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="-"
|
android:text="-"
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
android:phoneNumber="true"
|
android:phoneNumber="true"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Button
|
<com.TwentyCode.android.ExaltedDice.NumberPickerButton
|
||||||
android:id="@+id/up"
|
android:id="@+id/up"
|
||||||
android:layout_width="60px"
|
android:layout_width="60px"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import android.app.AlertDialog;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@@ -26,28 +27,39 @@ import android.widget.AdapterView.OnItemClickListener;
|
|||||||
|
|
||||||
public class ExaltedDice extends Activity implements OnClickListener, OnLongClickListener, OnItemClickListener {
|
public class ExaltedDice extends Activity implements OnClickListener, OnLongClickListener, OnItemClickListener {
|
||||||
|
|
||||||
// view variables
|
|
||||||
private TextView dice;
|
private TextView dice;
|
||||||
private ListView listview;
|
private ListView listview;
|
||||||
|
|
||||||
// exalted dice variables
|
|
||||||
private int intSuccesses;
|
|
||||||
public int intDice;
|
|
||||||
|
|
||||||
private ArrayList<String> rollHistory = new ArrayList<String>();
|
private ArrayList<String> rollHistory = new ArrayList<String>();
|
||||||
private ArrayList<Integer> rolled = new ArrayList<Integer>();
|
private ArrayList<Integer> rolled = new ArrayList<Integer>();
|
||||||
|
|
||||||
/**
|
private int intSuccesses;
|
||||||
* tag for LogCat
|
private int mCurrent;
|
||||||
*/
|
private static boolean mIncrement;
|
||||||
private static final String tag = "ExaltedDice";
|
private static boolean mDecrement;
|
||||||
|
|
||||||
/**
|
//the speed in milliseconds for dice increment or decrement
|
||||||
* set view id's
|
private long mSpeed = 300;
|
||||||
*/
|
|
||||||
private final int ADD_DICE = R.id.up;
|
//the least and most dice allowed
|
||||||
private final int SUB_DICE = R.id.down;
|
private int mStart = 1;
|
||||||
private final int ROLL_DICE = R.id.roll;
|
private int mEnd = 999;
|
||||||
|
|
||||||
|
private Handler mHandler;
|
||||||
|
//this runnable will be used to increment or decrement the amount of dice being rolled
|
||||||
|
private final Runnable mRunnable = new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
if (mIncrement) {
|
||||||
|
changeCurrent(mCurrent + 1);
|
||||||
|
mHandler.postDelayed(this, mSpeed);
|
||||||
|
} else if (mDecrement) {
|
||||||
|
changeCurrent(mCurrent - 1);
|
||||||
|
mHandler.postDelayed(this, mSpeed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final String TAG = "ExaltedDice";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* menu options
|
* menu options
|
||||||
@@ -57,57 +69,17 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
|
|
||||||
protected PostMortemReportExceptionHandler mDamageReport = new PostMortemReportExceptionHandler(this);
|
protected PostMortemReportExceptionHandler mDamageReport = new PostMortemReportExceptionHandler(this);
|
||||||
|
|
||||||
/**
|
protected void changeCurrent(int current) {
|
||||||
* adds one dice
|
// Wrap around the values if we go past the start or end
|
||||||
*
|
if (current > mEnd) {
|
||||||
* @author ricky barrette 3-27-2010
|
current = mStart;
|
||||||
*/
|
} else if (current < mStart) {
|
||||||
public void addDiceRolled() {
|
current = mEnd;
|
||||||
Log.i(tag, " addDiceRolled()");
|
|
||||||
|
|
||||||
// vibrate for 50 milliseconds
|
|
||||||
vibrate(50);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get string from dice textfield it convert it into int, while checking
|
|
||||||
* for user input errors
|
|
||||||
*/
|
|
||||||
intDice = checkForErrors((dice.getText()).toString());
|
|
||||||
|
|
||||||
// add 1 dice
|
|
||||||
intDice = moreDice(intDice, 1);
|
|
||||||
|
|
||||||
// set Dice textfield to finDice
|
|
||||||
dice.setText("" + intDice);
|
|
||||||
System.gc();
|
|
||||||
}
|
}
|
||||||
|
mCurrent = current;
|
||||||
/**
|
dice.setText("" + mCurrent);
|
||||||
* add 10 dice 3-27-2010
|
|
||||||
*
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public void addDiceRolledonLongClick() {
|
|
||||||
Log.i(tag, "addDiceRolledonLongClick()");
|
|
||||||
|
|
||||||
// vibrate for 75 milliseconds
|
|
||||||
vibrate(75);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get string from dice textfield it convert it into int, while checking
|
|
||||||
* for user input errors
|
|
||||||
*/
|
|
||||||
intDice = checkForErrors((dice.getText()).toString());
|
|
||||||
|
|
||||||
// add 10 dice
|
|
||||||
intDice = moreDice(intDice, 10);
|
|
||||||
|
|
||||||
// set Dice textfield to finDice
|
|
||||||
dice.setText("" + intDice);
|
|
||||||
System.gc();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* checks for the following errors:
|
* checks for the following errors:
|
||||||
*
|
*
|
||||||
@@ -133,7 +105,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public int checkForErrors(String string) {
|
public int checkForErrors(String string) {
|
||||||
Log.i(tag, "checkForErrors()");
|
Log.i(TAG, "checkForErrors()");
|
||||||
|
|
||||||
int numDice = 0;
|
int numDice = 0;
|
||||||
char charDice;
|
char charDice;
|
||||||
@@ -213,7 +185,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
*/
|
*/
|
||||||
if (errors == true)
|
if (errors == true)
|
||||||
toastLong("You inputed: \" " + string
|
toastLong("You inputed: \" " + string
|
||||||
+ " \", we are assuming you meant: "
|
+ " \", we think you meant: "
|
||||||
+ stringDice.toString());
|
+ stringDice.toString());
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------------
|
||||||
@@ -251,59 +223,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
listview.setAdapter(new ArrayAdapter<String>(this, R.layout.list_row, rollHistory));
|
listview.setAdapter(new ArrayAdapter<String>(this, R.layout.list_row, rollHistory));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Lower Dice Count By what ever lowerBy is, can't go lower than 1
|
|
||||||
*
|
|
||||||
* @param int number
|
|
||||||
* @return int number
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public int lessDice(int number, int lowerBy) {
|
|
||||||
Log.i(tag, "lessDice()");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* make sure we are not going to go negative
|
|
||||||
*/
|
|
||||||
if (number <= lowerBy)
|
|
||||||
lowerBy = number - 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* cant roll less than 1 dice
|
|
||||||
*/
|
|
||||||
if (number > 1)
|
|
||||||
number = number - lowerBy;
|
|
||||||
|
|
||||||
System.gc();
|
|
||||||
return number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Raise Dice Count By what ever raiseBy is, can't go higher than 999
|
|
||||||
*
|
|
||||||
* @param int number
|
|
||||||
* @return int number
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public int moreDice(int number, int raiseBy) {
|
|
||||||
Log.i(tag, "moreDice()");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* make sure we are not going to go higher than 999
|
|
||||||
*/
|
|
||||||
if (number > 989)
|
|
||||||
if (raiseBy > (number - 989))
|
|
||||||
raiseBy = 999 - number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Can not roll more than 999 dice
|
|
||||||
*/
|
|
||||||
if (number < 999)
|
|
||||||
number = number + raiseBy;
|
|
||||||
|
|
||||||
System.gc();
|
|
||||||
return number;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* also implemented OnClickListener
|
* also implemented OnClickListener
|
||||||
*
|
*
|
||||||
@@ -311,17 +230,15 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
* @author - WWPowers 3-26-2010
|
* @author - WWPowers 3-26-2010
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v){
|
||||||
|
if (v.getId() == R.id.up)
|
||||||
|
changeCurrent(mCurrent + 1);
|
||||||
|
|
||||||
if (v.getId() == ADD_DICE)
|
if (v.getId() == R.id.down)
|
||||||
addDiceRolled();
|
changeCurrent(mCurrent - 1);
|
||||||
|
|
||||||
if (v.getId() == SUB_DICE)
|
if (v.getId() == R.id.roll)
|
||||||
subtractDiceRolled();
|
|
||||||
|
|
||||||
if (v.getId() == ROLL_DICE)
|
|
||||||
rollDice();
|
rollDice();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -335,41 +252,27 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
Thread.setDefaultUncaughtExceptionHandler(mDamageReport);
|
Thread.setDefaultUncaughtExceptionHandler(mDamageReport);
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
Log.i(tag, "onCreate()");
|
Log.i(TAG, "onCreate()");
|
||||||
setContentView(R.layout.main);
|
setContentView(R.layout.main);
|
||||||
|
|
||||||
/**
|
mHandler = new Handler();
|
||||||
* TextViews
|
|
||||||
|
/*
|
||||||
|
* views and listeners
|
||||||
*/
|
*/
|
||||||
dice = (TextView) findViewById(R.id.dice);
|
dice = (TextView) findViewById(R.id.dice);
|
||||||
|
|
||||||
/**
|
|
||||||
* ListViews
|
|
||||||
*/
|
|
||||||
listview = (ListView) findViewById(R.id.list);
|
listview = (ListView) findViewById(R.id.list);
|
||||||
|
NumberPickerButton btAddDice = (NumberPickerButton) findViewById(R.id.up);
|
||||||
/**
|
NumberPickerButton btSubtractDice = (NumberPickerButton) findViewById(R.id.down);
|
||||||
* Buttons
|
|
||||||
*/
|
|
||||||
Button btAddDice = (Button) findViewById(R.id.up);
|
|
||||||
Button btSubtractDice = (Button) findViewById(R.id.down);
|
|
||||||
Button btRollDice = (Button) findViewById(R.id.roll);
|
Button btRollDice = (Button) findViewById(R.id.roll);
|
||||||
|
|
||||||
/**
|
|
||||||
* onClickListeners
|
|
||||||
*/
|
|
||||||
btAddDice.setOnClickListener(this);
|
btAddDice.setOnClickListener(this);
|
||||||
btSubtractDice.setOnClickListener(this);
|
btSubtractDice.setOnClickListener(this);
|
||||||
btRollDice.setOnClickListener(this);
|
btRollDice.setOnClickListener(this);
|
||||||
listview.setOnItemClickListener(this);
|
listview.setOnItemClickListener(this);
|
||||||
|
|
||||||
/**
|
|
||||||
* onLongClickListeners
|
|
||||||
*/
|
|
||||||
btAddDice.setOnLongClickListener(this);
|
btAddDice.setOnLongClickListener(this);
|
||||||
btSubtractDice.setOnLongClickListener(this);
|
btSubtractDice.setOnLongClickListener(this);
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* shake Listener
|
* shake Listener
|
||||||
*/
|
*/
|
||||||
// ShakeListener mShaker = new ShakeListener(this);
|
// ShakeListener mShaker = new ShakeListener(this);
|
||||||
@@ -379,14 +282,14 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* hide keyboard
|
* hide keyboard
|
||||||
*
|
*
|
||||||
* works on the emulator
|
* works on the emulator
|
||||||
*/
|
*/
|
||||||
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(dice.getWindowToken(), 0);
|
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(dice.getWindowToken(), 0);
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* display hello message
|
* display hello message
|
||||||
*/
|
*/
|
||||||
listview.setAdapter(new ArrayAdapter<String>(this, R.layout.list_row, getResources().getStringArray(R.array.hello_msg)));
|
listview.setAdapter(new ArrayAdapter<String>(this, R.layout.list_row, getResources().getStringArray(R.array.hello_msg)));
|
||||||
@@ -411,26 +314,27 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
|
public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) {
|
||||||
if(rolled.size() != 0){
|
if(rolled.size() != 0){
|
||||||
dice.setText("" + rolled.get(arg2));
|
dice.setText("" + rolled.get(position));
|
||||||
rollDice();
|
rollDice();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* also implemented OnLongClickListener
|
* starts a runnable that will increment or decrement the dice
|
||||||
*
|
*
|
||||||
* @author ricky barrette 3-27-2010
|
* @author ricky barrette 3-27-2010
|
||||||
* @param v
|
* @param v
|
||||||
*/
|
*/
|
||||||
public boolean onLongClick(View v) {
|
public boolean onLongClick(View v) {
|
||||||
if (v.getId() == ADD_DICE) {
|
if (v.getId() == R.id.up) {
|
||||||
addDiceRolledonLongClick();
|
mIncrement = true;
|
||||||
|
mHandler.post(mRunnable);
|
||||||
} else if (v.getId() == SUB_DICE) {
|
|
||||||
subtractDiceRolledonLongClick();
|
|
||||||
|
|
||||||
|
} else if (v.getId() == R.id.down) {
|
||||||
|
mDecrement = true;
|
||||||
|
mHandler.post(mRunnable);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -457,18 +361,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* pauses ShakeListener
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
Log.i(tag, "onPause()");
|
|
||||||
super.onPause();
|
|
||||||
// ShakeListener mShaker = new ShakeListener(this);
|
|
||||||
// mShaker.pause();
|
|
||||||
System.gc();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* resorts application state after rotation
|
* resorts application state after rotation
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
@@ -484,17 +376,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
listview.setAdapter(new ArrayAdapter<String>(this, R.layout.list_row, rollHistory));
|
listview.setAdapter(new ArrayAdapter<String>(this, R.layout.list_row, rollHistory));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* resumes ShakeListener
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
Log.i(tag, "onResume()");
|
|
||||||
super.onResume();
|
|
||||||
// ShakeListener mShaker = new ShakeListener(this);
|
|
||||||
// mShaker.resume();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* saves application state before rotatoin
|
* saves application state before rotatoin
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
@@ -510,20 +391,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
super.onSaveInstanceState(savedInstanceState);
|
super.onSaveInstanceState(savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* unregisters ShakeListener
|
|
||||||
*
|
|
||||||
* @author ricky barrette 3-26-2010
|
|
||||||
* @author WWPpwers 3-27-2010
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onStop() {
|
|
||||||
Log.i(tag, "onStop()");
|
|
||||||
super.onStop();
|
|
||||||
System.gc();
|
|
||||||
// ExaltedDice.this.finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* displays a quit dialog
|
* displays a quit dialog
|
||||||
*
|
*
|
||||||
@@ -555,7 +422,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
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();
|
||||||
resultsString.append("Rolled "+ times +" dice\n");
|
resultsString.append("Rolled "+ times +" dice\n");
|
||||||
|
|
||||||
@@ -577,7 +444,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
resultsString.append(roll[i] + ", ");
|
resultsString.append(roll[i] + ", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
System.gc();
|
|
||||||
return resultsString.toString();
|
return resultsString.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -594,17 +460,15 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
* get string from dice textfield it convert it into int, while checking
|
* get string from dice textfield it convert it into int, while checking
|
||||||
* for user input errors
|
* for user input errors
|
||||||
*/
|
*/
|
||||||
intDice = checkForErrors((dice.getText()).toString());
|
mCurrent = checkForErrors((dice.getText()).toString());
|
||||||
|
|
||||||
// set Dice textfield to finDice
|
// set Dice textfield to finDice
|
||||||
dice.setText("" + intDice);
|
dice.setText("" + mCurrent);
|
||||||
|
|
||||||
rolled.add(0, intDice);
|
rolled.add(0, mCurrent);
|
||||||
rollHistory.add(0, results(intDice));
|
rollHistory.add(0, results(mCurrent));
|
||||||
|
|
||||||
listview.setAdapter(new ArrayAdapter<String>(this, R.layout.list_row, rollHistory));
|
listview.setAdapter(new ArrayAdapter<String>(this, R.layout.list_row, rollHistory));
|
||||||
|
|
||||||
System.gc();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -615,68 +479,15 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public int[] rollGen(int times) {
|
public int[] rollGen(int times) {
|
||||||
Log.i(tag, "rollGen()" + times);
|
Log.i(TAG, "rollGen()" + times);
|
||||||
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(10) + 1;
|
roll[i] = random.nextInt(10) + 1;
|
||||||
}
|
}
|
||||||
System.gc();
|
|
||||||
return roll;
|
return roll;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* subtracts one dice 3-27-2010
|
|
||||||
*
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public void subtractDiceRolled() {
|
|
||||||
Log.i(tag, "subtractDice()");
|
|
||||||
;
|
|
||||||
|
|
||||||
// vibrate for 50 milliseconds
|
|
||||||
vibrate(50);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get string from dice textfield it convert it into int, while checking
|
|
||||||
* for user input errors
|
|
||||||
*/
|
|
||||||
intDice = checkForErrors((dice.getText()).toString());
|
|
||||||
|
|
||||||
// subtract 1 dice
|
|
||||||
intDice = lessDice(intDice, 1);
|
|
||||||
|
|
||||||
// set Dice textfield to finDice
|
|
||||||
dice.setText("" + intDice);
|
|
||||||
System.gc();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* subtracts 10 dice
|
|
||||||
*
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public void subtractDiceRolledonLongClick() {
|
|
||||||
Log.i(tag, "subtractDiceonLongClick()");
|
|
||||||
|
|
||||||
// vibrate for 75 milliseconds
|
|
||||||
vibrate(75);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get string from dice textfield it convert it into int, while checking
|
|
||||||
* for user input errors
|
|
||||||
*/
|
|
||||||
intDice = checkForErrors((dice.getText()).toString());
|
|
||||||
|
|
||||||
// subtract 10 dice
|
|
||||||
intDice = lessDice(intDice, 10);
|
|
||||||
|
|
||||||
// set Dice textfield to finDice
|
|
||||||
dice.setText("" + intDice);
|
|
||||||
System.gc();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* counts each dice roll that is greater than or equal to 7 as a success. 10
|
* counts each dice roll that is greater than or equal to 7 as a success. 10
|
||||||
* gets another success (for a total of 2)
|
* gets another success (for a total of 2)
|
||||||
@@ -686,7 +497,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public int successes(int[] roll) {
|
public int successes(int[] roll) {
|
||||||
Log.i(tag, "successes()");
|
Log.i(TAG, "successes()");
|
||||||
intSuccesses = 0;
|
intSuccesses = 0;
|
||||||
for (int i = 0; i < roll.length; i++) {
|
for (int i = 0; i < roll.length; i++) {
|
||||||
if (roll[i] >= 7)
|
if (roll[i] >= 7)
|
||||||
@@ -694,7 +505,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
if (roll[i] == 10)
|
if (roll[i] == 10)
|
||||||
intSuccesses++;
|
intSuccesses++;
|
||||||
}
|
}
|
||||||
System.gc();
|
|
||||||
return intSuccesses;
|
return intSuccesses;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -706,9 +516,8 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
* @author WWPowers 3-26-2010
|
* @author WWPowers 3-26-2010
|
||||||
*/
|
*/
|
||||||
public void toastLong(CharSequence msg) {
|
public void toastLong(CharSequence msg) {
|
||||||
Log.i(tag, "toastLong()");
|
Log.i(TAG, "toastLong()");
|
||||||
Toast toast = Toast.makeText(this, msg, Toast.LENGTH_LONG);
|
Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
|
||||||
toast.show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -719,7 +528,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
* @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
|
* start vibrator service
|
||||||
*/
|
*/
|
||||||
@@ -731,4 +540,21 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
vib.vibrate(milliseconds);
|
vib.vibrate(milliseconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stop incrementing of dice after longpress
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public static void cancelIncrement() {
|
||||||
|
mIncrement = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stops decrementing of dice after longpress
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
public static void cancelDecrement() {
|
||||||
|
mDecrement = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
/**
|
||||||
|
* @author Twenty Codes, LLC
|
||||||
|
* @author ricky barrette
|
||||||
|
* @date Sep 20, 2010
|
||||||
|
*
|
||||||
|
* Source from com.android.internal.widget.NumberPickerButton;
|
||||||
|
* Copyright (C) 2008 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package com.TwentyCode.android.ExaltedDice;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class exists purely to cancel long click events.
|
||||||
|
*/
|
||||||
|
public class NumberPickerButton extends Button {
|
||||||
|
|
||||||
|
public NumberPickerButton(Context context, AttributeSet attrs, int defStyle) {
|
||||||
|
super(context, attrs, defStyle);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NumberPickerButton(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NumberPickerButton(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
|
cancelLongpressIfRequired(event);
|
||||||
|
return super.onTouchEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTrackballEvent(MotionEvent event) {
|
||||||
|
cancelLongpressIfRequired(event);
|
||||||
|
return super.onTrackballEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||||
|
if ((keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
|
||||||
|
|| (keyCode == KeyEvent.KEYCODE_ENTER)) {
|
||||||
|
cancelLongpress();
|
||||||
|
}
|
||||||
|
return super.onKeyUp(keyCode, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cancelLongpressIfRequired(MotionEvent event) {
|
||||||
|
if ((event.getAction() == MotionEvent.ACTION_CANCEL)
|
||||||
|
|| (event.getAction() == MotionEvent.ACTION_UP)) {
|
||||||
|
cancelLongpress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cancelLongpress() {
|
||||||
|
if (R.id.up == getId()) {
|
||||||
|
ExaltedDice.cancelIncrement();
|
||||||
|
} else if (R.id.down == getId()) {
|
||||||
|
ExaltedDice.cancelDecrement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user