Add special touch zone to Joystick driver.

This commit is contained in:
James Sanford 2012-12-21 19:57:07 -08:00
parent 54108c346f
commit f5f5a3b70b
2 changed files with 16 additions and 5 deletions

View File

@ -392,13 +392,17 @@ public class KegsMain extends SherlockFragmentActivity implements KegsKeyboard.S
updateActionBar(bitmapSize.showActionBar());
mKegsView.updateScreenSize(bitmapSize);
mKegsTouch.setSpecialZone(
new TouchSpecialZone(getSpecialActionBarRect(bitmapSize)) {
// Update special click zone that toggles the ActionBar.
final TouchSpecialZone zone = new TouchSpecialZone(getSpecialActionBarRect(bitmapSize)) {
public void activate() {
mOverrideActionBar = !mOverrideActionBar;
updateActionBar(mOverrideActionBar);
}
});
};
mKegsTouch.setSpecialZone(zone);
mJoystick.setSpecialZone(zone);
// Force another redraw of the bitmap into the canvas. Bug workaround.
getThread().updateScreen();

View File

@ -13,6 +13,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
class TouchJoystick {
private ConcurrentLinkedQueue mEventQueue;
private TouchSpecialZone mSpecialZone = null;
private int mTouchSlop;
private int mMotionPointer = -1; // active pointer Id
@ -33,6 +34,10 @@ class TouchJoystick {
// mTouchSlop = configuration.getScaledTouchSlop();
}
public void setSpecialZone(TouchSpecialZone zone) {
mSpecialZone = zone;
}
private void reset_tracks(boolean resetA, boolean resetB) {
if (resetA && trackA != null) {
trackA.recycle();
@ -134,8 +139,10 @@ class TouchJoystick {
if (mMotionPointer == -1) {
// No active movement, assume this click/release should be a button press/release.
// TODO it probably shouldn't be sent if they had their finger down for more than 500ms or so.
mButton1 = 1;
mEventQueue.add(new Event.JoystickKegsEvent(0xFFFF, 0xFFFF, mButton1));
if (mSpecialZone != null && !mSpecialZone.click(e, pointerId)) {
mButton1 = 1;
mEventQueue.add(new Event.JoystickKegsEvent(0xFFFF, 0xFFFF, mButton1));
}
}
// SEND JOYSTICK BUTTON UP
mButton1 = 0;