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"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
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">
|
||||
<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"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button android:id="@+id/down"
|
||||
<com.TwentyCode.android.ExaltedDice.NumberPickerButton android:id="@+id/down"
|
||||
android:layout_width="60px"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="-"
|
||||
@@ -27,7 +27,7 @@
|
||||
android:phoneNumber="true"
|
||||
/>
|
||||
|
||||
<Button
|
||||
<com.TwentyCode.android.ExaltedDice.NumberPickerButton
|
||||
android:id="@+id/up"
|
||||
android:layout_width="60px"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Vibrator;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
@@ -26,28 +27,39 @@ import android.widget.AdapterView.OnItemClickListener;
|
||||
|
||||
public class ExaltedDice extends Activity implements OnClickListener, OnLongClickListener, OnItemClickListener {
|
||||
|
||||
// view variables
|
||||
private TextView dice;
|
||||
private ListView listview;
|
||||
|
||||
// exalted dice variables
|
||||
private int intSuccesses;
|
||||
public int intDice;
|
||||
|
||||
private ArrayList<String> rollHistory = new ArrayList<String>();
|
||||
private ArrayList<Integer> rolled = new ArrayList<Integer>();
|
||||
|
||||
/**
|
||||
* tag for LogCat
|
||||
*/
|
||||
private static final String tag = "ExaltedDice";
|
||||
private int intSuccesses;
|
||||
private int mCurrent;
|
||||
private static boolean mIncrement;
|
||||
private static boolean mDecrement;
|
||||
|
||||
/**
|
||||
* set view id's
|
||||
*/
|
||||
private final int ADD_DICE = R.id.up;
|
||||
private final int SUB_DICE = R.id.down;
|
||||
private final int ROLL_DICE = R.id.roll;
|
||||
//the speed in milliseconds for dice increment or decrement
|
||||
private long mSpeed = 300;
|
||||
|
||||
//the least and most dice allowed
|
||||
private int mStart = 1;
|
||||
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
|
||||
@@ -57,57 +69,17 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
||||
|
||||
protected PostMortemReportExceptionHandler mDamageReport = new PostMortemReportExceptionHandler(this);
|
||||
|
||||
/**
|
||||
* adds one dice
|
||||
*
|
||||
* @author ricky barrette 3-27-2010
|
||||
*/
|
||||
public void addDiceRolled() {
|
||||
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();
|
||||
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;
|
||||
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:
|
||||
*
|
||||
@@ -133,7 +105,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public int checkForErrors(String string) {
|
||||
Log.i(tag, "checkForErrors()");
|
||||
Log.i(TAG, "checkForErrors()");
|
||||
|
||||
int numDice = 0;
|
||||
char charDice;
|
||||
@@ -213,7 +185,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
||||
*/
|
||||
if (errors == true)
|
||||
toastLong("You inputed: \" " + string
|
||||
+ " \", we are assuming you meant: "
|
||||
+ " \", we think you meant: "
|
||||
+ 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));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
@@ -311,17 +230,15 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
||||
* @author - WWPowers 3-26-2010
|
||||
*/
|
||||
@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)
|
||||
addDiceRolled();
|
||||
if (v.getId() == R.id.down)
|
||||
changeCurrent(mCurrent - 1);
|
||||
|
||||
if (v.getId() == SUB_DICE)
|
||||
subtractDiceRolled();
|
||||
|
||||
if (v.getId() == ROLL_DICE)
|
||||
if (v.getId() == R.id.roll)
|
||||
rollDice();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -335,41 +252,27 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
||||
Thread.setDefaultUncaughtExceptionHandler(mDamageReport);
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
Log.i(tag, "onCreate()");
|
||||
Log.i(TAG, "onCreate()");
|
||||
setContentView(R.layout.main);
|
||||
|
||||
/**
|
||||
* TextViews
|
||||
mHandler = new Handler();
|
||||
|
||||
/*
|
||||
* views and listeners
|
||||
*/
|
||||
dice = (TextView) findViewById(R.id.dice);
|
||||
|
||||
/**
|
||||
* ListViews
|
||||
*/
|
||||
listview = (ListView) findViewById(R.id.list);
|
||||
|
||||
/**
|
||||
* Buttons
|
||||
*/
|
||||
Button btAddDice = (Button) findViewById(R.id.up);
|
||||
Button btSubtractDice = (Button) findViewById(R.id.down);
|
||||
NumberPickerButton btAddDice = (NumberPickerButton) findViewById(R.id.up);
|
||||
NumberPickerButton btSubtractDice = (NumberPickerButton) findViewById(R.id.down);
|
||||
Button btRollDice = (Button) findViewById(R.id.roll);
|
||||
|
||||
/**
|
||||
* onClickListeners
|
||||
*/
|
||||
btAddDice.setOnClickListener(this);
|
||||
btSubtractDice.setOnClickListener(this);
|
||||
btRollDice.setOnClickListener(this);
|
||||
listview.setOnItemClickListener(this);
|
||||
|
||||
/**
|
||||
* onLongClickListeners
|
||||
*/
|
||||
btAddDice.setOnLongClickListener(this);
|
||||
btSubtractDice.setOnLongClickListener(this);
|
||||
|
||||
/**
|
||||
/*
|
||||
* shake Listener
|
||||
*/
|
||||
// ShakeListener mShaker = new ShakeListener(this);
|
||||
@@ -379,14 +282,14 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
||||
// }
|
||||
// });
|
||||
|
||||
/**
|
||||
/*
|
||||
* hide keyboard
|
||||
*
|
||||
* works on the emulator
|
||||
*/
|
||||
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(dice.getWindowToken(), 0);
|
||||
|
||||
/**
|
||||
/*
|
||||
* display hello message
|
||||
*/
|
||||
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
|
||||
*/
|
||||
@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){
|
||||
dice.setText("" + rolled.get(arg2));
|
||||
dice.setText("" + rolled.get(position));
|
||||
rollDice();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* also implemented OnLongClickListener
|
||||
* starts a runnable that will increment or decrement the dice
|
||||
*
|
||||
* @author ricky barrette 3-27-2010
|
||||
* @param v
|
||||
*/
|
||||
public boolean onLongClick(View v) {
|
||||
if (v.getId() == ADD_DICE) {
|
||||
addDiceRolledonLongClick();
|
||||
|
||||
} else if (v.getId() == SUB_DICE) {
|
||||
subtractDiceRolledonLongClick();
|
||||
if (v.getId() == R.id.up) {
|
||||
mIncrement = true;
|
||||
mHandler.post(mRunnable);
|
||||
|
||||
} else if (v.getId() == R.id.down) {
|
||||
mDecrement = true;
|
||||
mHandler.post(mRunnable);
|
||||
} else {
|
||||
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
|
||||
* @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));
|
||||
}
|
||||
|
||||
/**
|
||||
* resumes ShakeListener
|
||||
*/
|
||||
@Override
|
||||
public void onResume() {
|
||||
Log.i(tag, "onResume()");
|
||||
super.onResume();
|
||||
// ShakeListener mShaker = new ShakeListener(this);
|
||||
// mShaker.resume();
|
||||
}
|
||||
|
||||
/**
|
||||
* saves application state before rotatoin
|
||||
* @author ricky barrette
|
||||
@@ -510,20 +391,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
||||
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
|
||||
*
|
||||
@@ -555,7 +422,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public String results(int times) {
|
||||
Log.i(tag, "results()");
|
||||
Log.i(TAG, "results()");
|
||||
StringBuffer resultsString = new StringBuffer();
|
||||
resultsString.append("Rolled "+ times +" dice\n");
|
||||
|
||||
@@ -577,7 +444,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
||||
resultsString.append(roll[i] + ", ");
|
||||
}
|
||||
|
||||
System.gc();
|
||||
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
|
||||
* for user input errors
|
||||
*/
|
||||
intDice = checkForErrors((dice.getText()).toString());
|
||||
mCurrent = checkForErrors((dice.getText()).toString());
|
||||
|
||||
// set Dice textfield to finDice
|
||||
dice.setText("" + intDice);
|
||||
dice.setText("" + mCurrent);
|
||||
|
||||
rolled.add(0, intDice);
|
||||
rollHistory.add(0, results(intDice));
|
||||
rolled.add(0, mCurrent);
|
||||
rollHistory.add(0, results(mCurrent));
|
||||
|
||||
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
|
||||
*/
|
||||
public int[] rollGen(int times) {
|
||||
Log.i(tag, "rollGen()" + times);
|
||||
Log.i(TAG, "rollGen()" + times);
|
||||
int[] roll = new int[times];
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < times; i++) {
|
||||
roll[i] = random.nextInt(10) + 1;
|
||||
}
|
||||
System.gc();
|
||||
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
|
||||
* gets another success (for a total of 2)
|
||||
@@ -686,7 +497,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public int successes(int[] roll) {
|
||||
Log.i(tag, "successes()");
|
||||
Log.i(TAG, "successes()");
|
||||
intSuccesses = 0;
|
||||
for (int i = 0; i < roll.length; i++) {
|
||||
if (roll[i] >= 7)
|
||||
@@ -694,7 +505,6 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
||||
if (roll[i] == 10)
|
||||
intSuccesses++;
|
||||
}
|
||||
System.gc();
|
||||
return intSuccesses;
|
||||
}
|
||||
|
||||
@@ -706,9 +516,8 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
||||
* @author WWPowers 3-26-2010
|
||||
*/
|
||||
public void toastLong(CharSequence msg) {
|
||||
Log.i(tag, "toastLong()");
|
||||
Toast toast = Toast.makeText(this, msg, Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
Log.i(TAG, "toastLong()");
|
||||
Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -719,7 +528,7 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public void vibrate(long milliseconds) {
|
||||
Log.i(tag, "vibrate() for " + milliseconds);
|
||||
Log.i(TAG, "vibrate() for " + milliseconds);
|
||||
/**
|
||||
* start vibrator service
|
||||
*/
|
||||
@@ -731,4 +540,21 @@ public class ExaltedDice extends Activity implements OnClickListener, OnLongClic
|
||||
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