ExaltedDice.java

i remove the field mFormater, interface Formatter, formatNumber() as they are not needed by exalted dice.
i removed getCurrent(), setCurrent() also because they were not used by exalted dice.
i modified onClick() and onLongClick() to use switch blocks rather than nested if else blocks
i incremented the version / build
from b12 to b13
This commit is contained in:
2010-09-22 11:41:48 +00:00
parent c0bd9fd839
commit ee36c22eda
5 changed files with 32 additions and 61 deletions

View File

@@ -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:versionCode="12" android:versionName="1.0.1"> android:versionName="1.0.1" android:versionCode="13">
<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"

View File

@@ -41,7 +41,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
private static boolean mDecrement; private static boolean mDecrement;
private InputFilter mNumberInputFilter; private InputFilter mNumberInputFilter;
private String[] mDisplayedValues; private String[] mDisplayedValues;
private Formatter mFormatter;
//the speed in milliseconds for dice increment or decrement //the speed in milliseconds for dice increment or decrement
private long mSpeed = 300; private long mSpeed = 300;
//the least and most dice allowed //the least and most dice allowed
@@ -51,7 +50,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
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 static final String TAG = "ExaltedDice";
private Handler mHandler; private Handler mHandler;
//this runnable will be used to increment or decrement the amount of dice being rolled //this runnable will be used to increment or decrement the amount of dice being rolled
private final Runnable mRunnable = new Runnable() { private final Runnable mRunnable = new Runnable() {
@@ -69,10 +67,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
private static final char[] DIGIT_CHARACTERS = new char[] { private static final char[] DIGIT_CHARACTERS = new char[] {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9' '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
}; };
public interface Formatter {
String toString(int value);
}
private class NumberPickerInputFilter implements InputFilter { private class NumberPickerInputFilter implements InputFilter {
public CharSequence filter(CharSequence source, int start, int end, public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) { Spanned dest, int dstart, int dend) {
@@ -103,9 +98,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
filtered = source.subSequence(start, end); filtered = source.subSequence(start, end);
} }
String result = String.valueOf(dest.subSequence(0, dstart)) String result = String.valueOf(dest.subSequence(0, dstart)) + filtered + dest.subSequence(dend, dest.length());
+ filtered
+ dest.subSequence(dend, dest.length());
if ("".equals(result)) { if ("".equals(result)) {
return result; return result;
@@ -153,7 +146,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
} }
protected void changeCurrent(int current) { protected void changeCurrent(int current) {
// Wrap around the values if we go past the start or end // Wrap around the values if we go past the start or end
if (current > mEnd) { if (current > mEnd) {
current = mStart; current = mStart;
@@ -175,19 +167,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));
} }
private String formatNumber(int value) {
return (mFormatter != null)
? mFormatter.toString(value)
: String.valueOf(value);
}
/**
* @return the current value.
*/
public int getCurrent() {
return mCurrent;
}
private int getSelectedPos(String str) { private int getSelectedPos(String str) {
if (mDisplayedValues == null) { if (mDisplayedValues == null) {
return Integer.parseInt(str); return Integer.parseInt(str);
@@ -230,14 +209,17 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
e.printStackTrace(); e.printStackTrace();
} }
if (v.getId() == R.id.up) switch (v.getId()){
changeCurrent(mCurrent + 1); case R.id.up:
changeCurrent(mCurrent + 1);
if (v.getId() == R.id.down) break;
changeCurrent(mCurrent - 1); case R.id.down:
changeCurrent(mCurrent - 1);
if (v.getId() == R.id.roll) break;
rollDice(); case R.id.roll:
rollDice();
break;
}
} }
/** /**
@@ -337,17 +319,18 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
e.printStackTrace(); e.printStackTrace();
} }
if (v.getId() == R.id.up) { switch (v.getId()){
mIncrement = true; case R.id.up:
mHandler.post(mRunnable); mIncrement = true;
mHandler.post(mRunnable);
} else if (v.getId() == R.id.down) { return true;
mDecrement = true;
mHandler.post(mRunnable); case R.id.down:
} else { mDecrement = true;
return false; mHandler.post(mRunnable);
return true;
} }
return true; return false;
} }
/** /**
@@ -384,9 +367,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
rolled = savedInstanceState.getIntegerArrayList("rolled"); rolled = savedInstanceState.getIntegerArrayList("rolled");
listview.setAdapter(new ArrayAdapter<String>(this, R.layout.list_row, rollHistory)); listview.setAdapter(new ArrayAdapter<String>(this, R.layout.list_row, rollHistory));
} }
/** /**
* saves application state before rotatoin * saves application state before rotatoin
* @author ricky barrette * @author ricky barrette
@@ -497,11 +478,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
return roll; return roll;
} }
public void setCurrent(int current) {
mCurrent = current;
updateView();
}
/** /**
* 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)
@@ -534,18 +510,13 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
Toast.makeText(this, msg, Toast.LENGTH_LONG).show(); Toast.makeText(this, msg, Toast.LENGTH_LONG).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() { protected void updateView() {
dice.setText(mCurrent+"");
/* If we don't have displayed values then use the
* current number else find the correct value in the
* displayed values for the current number.
*/
if (mDisplayedValues == null) {
dice.setText(formatNumber(mCurrent));
} else {
dice.setText(mDisplayedValues[mCurrent - mStart]);
}
dice.setSelection(dice.getText().length());
} }
/** /**