ExaltedDice.java

in the methods onClick(), onLongClick(), and rollDice() i added the following:
	try {
		mCurrent = Integer.parseInt(dice.getText().toString());
	} catch (NumberFormatException e) {
		e.printStackTrace();
	}
	
this finished the updated user input methods, based on the Android source code. the new input methods will only except numbers for entry. also the long press function 
now increments / decrements the amount of dice every 300 ms.

i incremented the version / build number 
from 1.0.0b12 to 1.0.1b13
This commit is contained in:
2010-09-21 23:40:56 +00:00
parent 890f1f04ff
commit c0bd9fd839
5 changed files with 26 additions and 53 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:versionName="1.0.0" android:versionCode="12"> android:versionCode="12" android:versionName="1.0.1">
<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

@@ -19,7 +19,6 @@ import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
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;
@@ -28,10 +27,9 @@ import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
public class ExaltedDice extends Activity implements OnClickListener, OnLongClickListener, OnItemClickListener, OnFocusChangeListener { public class ExaltedDice extends Activity implements OnClickListener, OnLongClickListener, OnItemClickListener {
private EditText dice; private EditText dice;
private ListView listview; private ListView listview;
@@ -43,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;
protected int mPrevious;
private Formatter mFormatter; 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;
@@ -83,8 +80,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
return mNumberInputFilter.filter(source, start, end, dest, dstart, dend); return mNumberInputFilter.filter(source, start, end, dest, dstart, dend);
} }
CharSequence filtered = String.valueOf(source.subSequence(start, end)); CharSequence filtered = String.valueOf(source.subSequence(start, end));
String result = String.valueOf(dest.subSequence(0, dstart)) String result = String.valueOf(dest.subSequence(0, dstart)) + filtered
+ filtered
+ dest.subSequence(dend, dest.length()); + dest.subSequence(dend, dest.length());
String str = String.valueOf(result).toLowerCase(); String str = String.valueOf(result).toLowerCase();
for (String val : mDisplayedValues) { for (String val : mDisplayedValues) {
@@ -164,7 +160,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
} else if (current < mStart) { } else if (current < mStart) {
current = mEnd; current = mEnd;
} }
mPrevious = mCurrent;
mCurrent = current; mCurrent = current;
updateView(); updateView();
} }
@@ -227,6 +222,14 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
*/ */
@Override @Override
public void onClick(View v){ public void onClick(View v){
//get the number from the edit text
try {
mCurrent = Integer.parseInt(dice.getText().toString());
} catch (NumberFormatException e) {
e.printStackTrace();
}
if (v.getId() == R.id.up) if (v.getId() == R.id.up)
changeCurrent(mCurrent + 1); changeCurrent(mCurrent + 1);
@@ -257,7 +260,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
* views and listeners * views and listeners
*/ */
dice = (EditText) findViewById(R.id.dice); dice = (EditText) findViewById(R.id.dice);
dice.setOnFocusChangeListener(this);
InputFilter inputFilter = new NumberPickerInputFilter(); InputFilter inputFilter = new NumberPickerInputFilter();
mNumberInputFilter = new NumberRangeKeyListener(); mNumberInputFilter = new NumberRangeKeyListener();
dice.setFilters(new InputFilter[] {inputFilter}); dice.setFilters(new InputFilter[] {inputFilter});
@@ -308,16 +310,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
return true; return true;
} }
public void onFocusChange(View v, boolean hasFocus) {
/* When focus is lost check that the text field
* has valid values.
*/
if (!hasFocus) {
validateInput(v);
}
}
/** /**
* rolls same amount of dice as previous roll * rolls same amount of dice as previous roll
* @author ricky barrette * @author ricky barrette
@@ -337,6 +329,14 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
* @param v * @param v
*/ */
public boolean onLongClick(View v) { public boolean onLongClick(View v) {
//get the number from the edit text
try {
mCurrent = Integer.parseInt(dice.getText().toString());
} catch (NumberFormatException e) {
e.printStackTrace();
}
if (v.getId() == R.id.up) { if (v.getId() == R.id.up) {
mIncrement = true; mIncrement = true;
mHandler.post(mRunnable); mHandler.post(mRunnable);
@@ -468,15 +468,12 @@ 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) {
// mCurrent = checkForErrors((dice.getText()).toString()); e.printStackTrace();
}
// set Dice textfield to finDice
dice.setText("" + mCurrent);
rolled.add(0, mCurrent); rolled.add(0, mCurrent);
rollHistory.add(0, results(mCurrent)); rollHistory.add(0, results(mCurrent));
@@ -551,30 +548,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
dice.setSelection(dice.getText().length()); dice.setSelection(dice.getText().length());
} }
private void validateCurrentView(CharSequence str) {
int val = getSelectedPos(str.toString());
if ((val >= mStart) && (val <= mEnd)) {
if (mCurrent != val) {
mPrevious = mCurrent;
mCurrent = val;
}
}
updateView();
}
private void validateInput(View v) {
String str = String.valueOf(((TextView) v).getText());
if ("".equals(str)) {
// Restore to the old value as we don't allow empty values
updateView();
} else {
// Check the new value and ensure it's in range
validateCurrentView(str);
}
}
/** /**
* starts Vibrator service and then vibrates for x milliseconds * starts Vibrator service and then vibrates for x milliseconds
* *