merge to branch for publication
This commit is contained in:
@@ -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.
@@ -10,4 +10,4 @@
|
|||||||
# Indicates whether an apk should be generated for each density.
|
# Indicates whether an apk should be generated for each density.
|
||||||
split.density=false
|
split.density=false
|
||||||
# Project target.
|
# Project target.
|
||||||
target=android-3
|
target=android-8
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string-array name="hello_msg"><item>Welcome to ExaltedDice!</item>
|
<string-array name="hello_msg"><item>Welcome to ExaltedDice!</item>
|
||||||
<item>Press the - button to lower your dice count by 1, or long press the - button to lower dice count by 10 </item><item>Press the + button to raise dice count by 1 of long press + to raise dice count by 10.</item><item>When you press Roll, Your Results Will Be Displayed Here</item>
|
<item>Press the - button to lower your dice count by 1, or long press to continuously lower the dice count.</item><item>Press the + button to raise your dice count by 1, or long press to continuously raise the dice count.</item><item>When you press Roll, Your Results Will Be Displayed Here</item>
|
||||||
|
|
||||||
|
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|||||||
@@ -8,7 +8,12 @@ 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.text.InputFilter;
|
||||||
|
import android.text.InputType;
|
||||||
|
import android.text.Spanned;
|
||||||
|
import android.text.method.NumberKeyListener;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@@ -17,227 +22,138 @@ import android.view.View.OnClickListener;
|
|||||||
import android.view.View.OnLongClickListener;
|
import android.view.View.OnLongClickListener;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
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 EditText 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;
|
||||||
/**
|
private int mCurrent;
|
||||||
* tag for LogCat
|
private static boolean mIncrement;
|
||||||
*/
|
private static boolean mDecrement;
|
||||||
private static final String tag = "ExaltedDice";
|
private InputFilter mNumberInputFilter;
|
||||||
|
private String[] mDisplayedValues;
|
||||||
/**
|
//the speed in milliseconds for dice increment or decrement
|
||||||
* set view id's
|
private long mSpeed = 300;
|
||||||
*/
|
//the least and most dice allowed
|
||||||
private final int ADD_DICE = R.id.up;
|
private int mStart = 1;
|
||||||
private final int SUB_DICE = R.id.down;
|
private int mEnd = 999;
|
||||||
private final int ROLL_DICE = R.id.roll;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* menu options
|
|
||||||
*/
|
|
||||||
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;
|
||||||
|
|
||||||
protected PostMortemReportExceptionHandler mDamageReport = new PostMortemReportExceptionHandler(this);
|
protected PostMortemReportExceptionHandler mDamageReport = new PostMortemReportExceptionHandler(this);
|
||||||
|
private static final String TAG = "ExaltedDice";
|
||||||
|
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 char[] DIGIT_CHARACTERS = new char[] {
|
||||||
* adds one dice
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
|
||||||
*
|
};
|
||||||
* @author ricky barrette 3-27-2010
|
|
||||||
|
private class NumberPickerInputFilter implements InputFilter {
|
||||||
|
public CharSequence filter(CharSequence source, int start, int end,
|
||||||
|
Spanned dest, int dstart, int dend) {
|
||||||
|
if (mDisplayedValues == null) {
|
||||||
|
return mNumberInputFilter.filter(source, start, end, dest, dstart, dend);
|
||||||
|
}
|
||||||
|
CharSequence filtered = String.valueOf(source.subSequence(start, end));
|
||||||
|
String result = String.valueOf(dest.subSequence(0, dstart)) + filtered
|
||||||
|
+ dest.subSequence(dend, dest.length());
|
||||||
|
String str = String.valueOf(result).toLowerCase();
|
||||||
|
for (String val : mDisplayedValues) {
|
||||||
|
val = val.toLowerCase();
|
||||||
|
if (val.startsWith(str)) {
|
||||||
|
return filtered;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class NumberRangeKeyListener extends NumberKeyListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
|
||||||
|
|
||||||
|
CharSequence filtered = super.filter(source, start, end, dest, dstart, dend);
|
||||||
|
if (filtered == null) {
|
||||||
|
filtered = source.subSequence(start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
String result = String.valueOf(dest.subSequence(0, dstart)) + filtered + dest.subSequence(dend, dest.length());
|
||||||
|
|
||||||
|
if ("".equals(result)) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
int val = getSelectedPos(result);
|
||||||
|
|
||||||
|
/* Ensure the user can't type in a value greater
|
||||||
|
* than the max allowed. We have to allow less than min
|
||||||
|
* as the user might want to delete some numbers
|
||||||
|
* and then type a new number.
|
||||||
*/
|
*/
|
||||||
public void addDiceRolled() {
|
if (val > mEnd) {
|
||||||
Log.i(tag, " addDiceRolled()");
|
return "";
|
||||||
|
} else {
|
||||||
|
return filtered;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// vibrate for 50 milliseconds
|
@Override
|
||||||
vibrate(50);
|
protected char[] getAcceptedChars() {
|
||||||
|
return DIGIT_CHARACTERS;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
// XXX This doesn't allow for range limits when controlled by a
|
||||||
* get string from dice textfield it convert it into int, while checking
|
// soft input method!
|
||||||
* for user input errors
|
public int getInputType() {
|
||||||
*/
|
return InputType.TYPE_CLASS_NUMBER;
|
||||||
intDice = checkForErrors((dice.getText()).toString());
|
}
|
||||||
|
|
||||||
// add 1 dice
|
|
||||||
intDice = moreDice(intDice, 1);
|
|
||||||
|
|
||||||
// set Dice textfield to finDice
|
|
||||||
dice.setText("" + intDice);
|
|
||||||
System.gc();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add 10 dice 3-27-2010
|
* stops decrementing of dice after longpress
|
||||||
*
|
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public void addDiceRolledonLongClick() {
|
public static void cancelDecrement() {
|
||||||
Log.i(tag, "addDiceRolledonLongClick()");
|
mDecrement = false;
|
||||||
|
|
||||||
// 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:
|
* stop incrementing of dice after longpress
|
||||||
*
|
|
||||||
* checks string if it is blank, if so changes string to "1"
|
|
||||||
*
|
|
||||||
* look at each char in string individually to see if int or not if the char
|
|
||||||
* is an in add it to stringDice, example: a string of "1.2-3" would result
|
|
||||||
* in a stringDice of "123"
|
|
||||||
*
|
|
||||||
* also if there are any zeros preceding an int, they will be removed
|
|
||||||
* example: a string of "000102" would result in a stringDice of "102"
|
|
||||||
*
|
|
||||||
* if there are any typos removed, use toast to inform the user that we
|
|
||||||
* assumed that when they typed "0001.2-3" they meant to type "123"
|
|
||||||
*
|
|
||||||
* limits stringDice to 3 chars (limiting the number of dice to 999) if
|
|
||||||
* stringDice is longer than 3 chars, it is changed to "1" also toast is
|
|
||||||
* displayed to inform user of the 999 dice rule.
|
|
||||||
*
|
|
||||||
* @param String
|
|
||||||
* string
|
|
||||||
* @return int numDice
|
|
||||||
* @author ricky barrette
|
* @author ricky barrette
|
||||||
*/
|
*/
|
||||||
public int checkForErrors(String string) {
|
public static void cancelIncrement() {
|
||||||
Log.i(tag, "checkForErrors()");
|
mIncrement = false;
|
||||||
|
|
||||||
int numDice = 0;
|
|
||||||
char charDice;
|
|
||||||
StringBuffer stringDice = new StringBuffer();
|
|
||||||
boolean errors = false;
|
|
||||||
boolean zeroCheck = true;
|
|
||||||
boolean isNumber = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* if textField is left blank, change value to 1
|
|
||||||
*/
|
|
||||||
if (string.length() == 0)
|
|
||||||
string += "" + 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* look at each char in string individually to see if int or not if the
|
|
||||||
* char is an in add it to stringDice, example: a string of "1.2-3"
|
|
||||||
* would result in a stringDice of "123"
|
|
||||||
*
|
|
||||||
* also if there are any zeros preceding an int, they also will be
|
|
||||||
* removed example: a string of "00-01.02" would result in a stringDice
|
|
||||||
* of "102"
|
|
||||||
*/
|
|
||||||
for (int i = 0; i < string.length(); i++) {
|
|
||||||
// get the char
|
|
||||||
charDice = string.charAt(i);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* try to parse the char, to see it it is an int or not.
|
|
||||||
*/
|
|
||||||
try {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* we are going to borrow numDice instead of creating another
|
|
||||||
* addressing space
|
|
||||||
*/
|
|
||||||
|
|
||||||
numDice = Integer.parseInt(Character.toString(charDice));
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* zero check to remove any zeros preceding an int value. true =
|
|
||||||
* zero check on, false = zero check off
|
|
||||||
*/
|
|
||||||
if (zeroCheck == true) {
|
|
||||||
if (numDice != 0) {
|
|
||||||
zeroCheck = false;
|
|
||||||
isNumber = true;
|
|
||||||
stringDice.append(numDice);
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
stringDice.append(numDice);
|
|
||||||
|
|
||||||
} catch (NumberFormatException nFE) {
|
|
||||||
errors = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void changeCurrent(int current) {
|
||||||
|
// Wrap around the values if we go past the start or end
|
||||||
|
if (current > mEnd) {
|
||||||
|
current = mStart;
|
||||||
|
} else if (current < mStart) {
|
||||||
|
current = mEnd;
|
||||||
}
|
}
|
||||||
|
mCurrent = current;
|
||||||
/**
|
updateView();
|
||||||
* notify user if there were no ints
|
|
||||||
*/
|
|
||||||
if (isNumber == false) {
|
|
||||||
toastLong("You inputed: \" "
|
|
||||||
+ string
|
|
||||||
+ " \", which contains no numbers, we will roll one dice for you.");
|
|
||||||
stringDice.append(1);
|
|
||||||
/**
|
|
||||||
* prevent error message from displaying
|
|
||||||
*/
|
|
||||||
errors = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* notify user if there were typos
|
|
||||||
*/
|
|
||||||
if (errors == true)
|
|
||||||
toastLong("You inputed: \" " + string
|
|
||||||
+ " \", we are assuming you meant: "
|
|
||||||
+ stringDice.toString());
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
|
||||||
* limit number to 999
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (stringDice.length() > 3) {
|
|
||||||
|
|
||||||
toastLong("Sorry, I can not roll " + stringDice
|
|
||||||
+ " dice. Try Rolling Between 1 - 999 dice.");
|
|
||||||
|
|
||||||
/**
|
|
||||||
* set number of dice to 1
|
|
||||||
*/
|
|
||||||
numDice = 1;
|
|
||||||
|
|
||||||
} else
|
|
||||||
numDice = Integer.parseInt(stringDice.toString());
|
|
||||||
|
|
||||||
stringDice = null;
|
|
||||||
System.gc();
|
|
||||||
return numDice;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -251,57 +167,30 @@ 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private int getSelectedPos(String str) {
|
||||||
* Lower Dice Count By what ever lowerBy is, can't go lower than 1
|
if (mDisplayedValues == null) {
|
||||||
*
|
return Integer.parseInt(str);
|
||||||
* @param int number
|
} else {
|
||||||
* @return int number
|
for (int i = 0; i < mDisplayedValues.length; i++) {
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
|
||||||
public int lessDice(int number, int lowerBy) {
|
|
||||||
Log.i(tag, "lessDice()");
|
|
||||||
|
|
||||||
/**
|
/* Don't force the user to type in jan when ja will do */
|
||||||
* make sure we are not going to go negative
|
str = str.toLowerCase();
|
||||||
*/
|
if (mDisplayedValues[i].toLowerCase().startsWith(str)) {
|
||||||
if (number <= lowerBy)
|
return mStart + i;
|
||||||
lowerBy = number - 1;
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* cant roll less than 1 dice
|
|
||||||
*/
|
|
||||||
if (number > 1)
|
|
||||||
number = number - lowerBy;
|
|
||||||
|
|
||||||
System.gc();
|
|
||||||
return number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/* The user might have typed in a number into the month field i.e.
|
||||||
* Raise Dice Count By what ever raiseBy is, can't go higher than 999
|
* 10 instead of OCT so support that too.
|
||||||
*
|
|
||||||
* @param int number
|
|
||||||
* @return int number
|
|
||||||
* @author ricky barrette
|
|
||||||
*/
|
*/
|
||||||
public int moreDice(int number, int raiseBy) {
|
try {
|
||||||
Log.i(tag, "moreDice()");
|
return Integer.parseInt(str);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
|
||||||
/**
|
/* Ignore as if it's not a number we don't care */
|
||||||
* make sure we are not going to go higher than 999
|
}
|
||||||
*/
|
}
|
||||||
if (number > 989)
|
return mStart;
|
||||||
if (raiseBy > (number - 989))
|
|
||||||
raiseBy = 999 - number;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Can not roll more than 999 dice
|
|
||||||
*/
|
|
||||||
if (number < 999)
|
|
||||||
number = number + raiseBy;
|
|
||||||
|
|
||||||
System.gc();
|
|
||||||
return number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -313,15 +202,24 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v){
|
public void onClick(View v){
|
||||||
|
|
||||||
if (v.getId() == ADD_DICE)
|
//get the number from the edit text
|
||||||
addDiceRolled();
|
try {
|
||||||
|
mCurrent = Integer.parseInt(dice.getText().toString());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
if (v.getId() == SUB_DICE)
|
switch (v.getId()){
|
||||||
subtractDiceRolled();
|
case R.id.up:
|
||||||
|
changeCurrent(mCurrent + 1);
|
||||||
if (v.getId() == ROLL_DICE)
|
break;
|
||||||
|
case R.id.down:
|
||||||
|
changeCurrent(mCurrent - 1);
|
||||||
|
break;
|
||||||
|
case R.id.roll:
|
||||||
rollDice();
|
rollDice();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -335,41 +233,31 @@ 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
|
|
||||||
*/
|
|
||||||
dice = (TextView) findViewById(R.id.dice);
|
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* ListViews
|
* views and listeners
|
||||||
*/
|
*/
|
||||||
|
dice = (EditText) findViewById(R.id.dice);
|
||||||
|
InputFilter inputFilter = new NumberPickerInputFilter();
|
||||||
|
mNumberInputFilter = new NumberRangeKeyListener();
|
||||||
|
dice.setFilters(new InputFilter[] {inputFilter});
|
||||||
|
|
||||||
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 +267,12 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* hide keyboard
|
* hide keyboard
|
||||||
*
|
|
||||||
* 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,30 +297,40 @@ 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) {
|
|
||||||
addDiceRolledonLongClick();
|
|
||||||
|
|
||||||
} else if (v.getId() == SUB_DICE) {
|
//get the number from the edit text
|
||||||
subtractDiceRolledonLongClick();
|
try {
|
||||||
|
mCurrent = Integer.parseInt(dice.getText().toString());
|
||||||
} else {
|
} catch (NumberFormatException e) {
|
||||||
return false;
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (v.getId()){
|
||||||
|
case R.id.up:
|
||||||
|
mIncrement = true;
|
||||||
|
mHandler.post(mRunnable);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
case R.id.down:
|
||||||
|
mDecrement = true;
|
||||||
|
mHandler.post(mRunnable);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -457,18 +353,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 +368,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,19 +383,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 +415,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 +437,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -590,21 +449,16 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
|||||||
// vibrate for 50 milliseconds
|
// vibrate for 50 milliseconds
|
||||||
vibrate(50);
|
vibrate(50);
|
||||||
|
|
||||||
/**
|
//get the number from the edit text
|
||||||
* get string from dice textfield it convert it into int, while checking
|
try {
|
||||||
* for user input errors
|
mCurrent = Integer.parseInt(dice.getText().toString());
|
||||||
*/
|
} catch (NumberFormatException e) {
|
||||||
intDice = checkForErrors((dice.getText()).toString());
|
e.printStackTrace();
|
||||||
|
}
|
||||||
// set Dice textfield to finDice
|
rolled.add(0, mCurrent);
|
||||||
dice.setText("" + intDice);
|
rollHistory.add(0, results(mCurrent));
|
||||||
|
|
||||||
rolled.add(0, intDice);
|
|
||||||
rollHistory.add(0, results(intDice));
|
|
||||||
|
|
||||||
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 +469,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 +487,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 +495,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 +506,17 @@ 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();
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a convince method that will update the edit text dice to what the current amount of dice is
|
||||||
|
*
|
||||||
|
* @author ricky barrette
|
||||||
|
*/
|
||||||
|
protected void updateView() {
|
||||||
|
dice.setText(mCurrent+"");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -719,7 +527,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
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,11 @@ import android.content.pm.PackageManager;
|
|||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dont forget the manifest tag
|
||||||
|
* <uses-permission android:name="android.permission.READ_LOGS" />
|
||||||
|
* @author ricky
|
||||||
|
*/
|
||||||
public class PostMortemReportExceptionHandler implements UncaughtExceptionHandler, Runnable {
|
public class PostMortemReportExceptionHandler implements UncaughtExceptionHandler, Runnable {
|
||||||
public static final String ExceptionReportFilename = "postmortem.trace";
|
public static final String ExceptionReportFilename = "postmortem.trace";
|
||||||
|
|
||||||
@@ -30,23 +35,13 @@ public class PostMortemReportExceptionHandler implements UncaughtExceptionHandle
|
|||||||
private Thread.UncaughtExceptionHandler mDefaultUEH;
|
private Thread.UncaughtExceptionHandler mDefaultUEH;
|
||||||
private Activity mApp = null;
|
private Activity mApp = null;
|
||||||
|
|
||||||
/*
|
|
||||||
* Constructor
|
|
||||||
*/
|
|
||||||
public PostMortemReportExceptionHandler(Activity aApp) {
|
public PostMortemReportExceptionHandler(Activity aApp) {
|
||||||
mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler();
|
mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler();
|
||||||
mApp = aApp;
|
mApp = aApp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void uncaughtException(Thread t, Throwable e) {
|
|
||||||
submit(e);
|
|
||||||
//do not forget to pass this exception through up the chain
|
|
||||||
mDefaultUEH.uncaughtException(t,e);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDebugReport(Throwable aException) {
|
public String getDebugReport(Throwable aException) {
|
||||||
|
|
||||||
// NumberFormat theFormatter = new DecimalFormat("#0.");
|
// NumberFormat theFormatter = new DecimalFormat("#0.");
|
||||||
//stack trace
|
//stack trace
|
||||||
StackTraceElement[] theStackTrace = aException.getStackTrace();
|
StackTraceElement[] theStackTrace = aException.getStackTrace();
|
||||||
@@ -120,11 +115,36 @@ public class PostMortemReportExceptionHandler implements UncaughtExceptionHandle
|
|||||||
}
|
}
|
||||||
report.append("-------------------------------\n\n");
|
report.append("-------------------------------\n\n");
|
||||||
|
|
||||||
|
report.append("--------- Complete Logcat ---------\n\n");
|
||||||
|
report.append(getLog().toString());
|
||||||
|
report.append("-------------------------------\n\n");
|
||||||
|
|
||||||
report.append("END REPORT");
|
report.append("END REPORT");
|
||||||
|
|
||||||
return report.toString();
|
return report.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected StringBuilder getLog(){
|
||||||
|
final StringBuilder log = new StringBuilder();
|
||||||
|
try{
|
||||||
|
Process process = Runtime.getRuntime().exec("logcat -d");
|
||||||
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
|
|
||||||
|
String line;
|
||||||
|
while ((line = bufferedReader.readLine()) != null){
|
||||||
|
log.append(line);
|
||||||
|
log.append("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e){
|
||||||
|
}
|
||||||
|
return log;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
sendDebugReportToAuthor();
|
||||||
|
}
|
||||||
|
|
||||||
protected void saveDebugReport(String aReport) {
|
protected void saveDebugReport(String aReport) {
|
||||||
//save report to file
|
//save report to file
|
||||||
try {
|
try {
|
||||||
@@ -140,7 +160,8 @@ public class PostMortemReportExceptionHandler implements UncaughtExceptionHandle
|
|||||||
String theLine = "";
|
String theLine = "";
|
||||||
StringBuffer theTrace = new StringBuffer();
|
StringBuffer theTrace = new StringBuffer();
|
||||||
try {
|
try {
|
||||||
BufferedReader theReader = new BufferedReader(new InputStreamReader(mApp.openFileInput(ExceptionReportFilename)));
|
BufferedReader theReader = new BufferedReader(
|
||||||
|
new InputStreamReader(mApp.openFileInput(ExceptionReportFilename)));
|
||||||
while ((theLine = theReader.readLine())!=null) {
|
while ((theLine = theReader.readLine())!=null) {
|
||||||
theTrace.append(theLine+"\n");
|
theTrace.append(theLine+"\n");
|
||||||
}
|
}
|
||||||
@@ -152,7 +173,6 @@ public class PostMortemReportExceptionHandler implements UncaughtExceptionHandle
|
|||||||
} catch(IOException eIo) {
|
} catch(IOException eIo) {
|
||||||
// not going to report
|
// not going to report
|
||||||
}
|
}
|
||||||
System.gc();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean sendDebugReportToAuthor(String aReport) {
|
public Boolean sendDebugReportToAuthor(String aReport) {
|
||||||
@@ -176,15 +196,16 @@ public class PostMortemReportExceptionHandler implements UncaughtExceptionHandle
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
sendDebugReportToAuthor();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void submit(Throwable e) {
|
public void submit(Throwable e) {
|
||||||
String theErrReport = getDebugReport(e);
|
String theErrReport = getDebugReport(e);
|
||||||
saveDebugReport(theErrReport);
|
saveDebugReport(theErrReport);
|
||||||
//try to send file contents via email (need to do so via the UI thread)
|
//try to send file contents via email (need to do so via the UI thread)
|
||||||
mApp.runOnUiThread(this);
|
mApp.runOnUiThread(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void uncaughtException(Thread t, Throwable e) {
|
||||||
|
submit(e);
|
||||||
|
//do not forget to pass this exception through up the chain
|
||||||
|
mDefaultUEH.uncaughtException(t,e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user