diff --git a/src/com/froop/app/kegs/BitmapSize.java b/src/com/froop/app/kegs/BitmapSize.java index 402176c..ec78307 100644 --- a/src/com/froop/app/kegs/BitmapSize.java +++ b/src/com/froop/app/kegs/BitmapSize.java @@ -67,6 +67,14 @@ class BitmapSize { } } + public int getScreenWidth() { + return mWidth; + } + + public int getScreenHeight() { + return mHeight; + } + public int getViewWidth() { return (int)(Const.A2Width * mScaleFactorX); } diff --git a/src/com/froop/app/kegs/KegsMain.java b/src/com/froop/app/kegs/KegsMain.java index 8759047..8da9c69 100644 --- a/src/com/froop/app/kegs/KegsMain.java +++ b/src/com/froop/app/kegs/KegsMain.java @@ -8,6 +8,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.res.Configuration; +import android.graphics.Rect; import android.net.Uri; import android.os.Bundle; import android.os.AsyncTask; @@ -49,7 +50,7 @@ public class KegsMain extends SherlockFragmentActivity implements KegsKeyboard.S private TouchJoystick mJoystick; private boolean mModeMouse = true; - + private boolean mOverrideActionBar = false; private long mScreenSizeTime = 0; private boolean mPaused = false; @@ -345,7 +346,24 @@ public class KegsMain extends SherlockFragmentActivity implements KegsKeyboard.S return mKegsThread; } + // Designate the upper right corner as a special zone that + // toggles the action bar. + private Rect getSpecialActionBarRect(BitmapSize bitmapSize) { + final int left = (int)(bitmapSize.getScreenWidth() * 0.80); + final int top = 0; + final int right = bitmapSize.getScreenWidth(); + final int bottom = (int)(bitmapSize.getScreenHeight() * 0.10); + + // Only have a special zone if the action bar is not supposed to be visible. + if (!bitmapSize.showActionBar() && left != 0 && bottom != 0) { + return new Rect(left, top, right, bottom); + } else { + return null; + } + } + private void updateActionBar(boolean showActionBar) { + showActionBar = mOverrideActionBar || showActionBar; final ActionBar actionBar = getSupportActionBar(); if (actionBar != null && showActionBar) { actionBar.show(); @@ -374,6 +392,13 @@ public class KegsMain extends SherlockFragmentActivity implements KegsKeyboard.S updateActionBar(bitmapSize.showActionBar()); mKegsView.updateScreenSize(bitmapSize); + mKegsTouch.setSpecialZone( + new TouchSpecialZone(getSpecialActionBarRect(bitmapSize)) { + public void activate() { + mOverrideActionBar = !mOverrideActionBar; + updateActionBar(mOverrideActionBar); + } + }); // Force another redraw of the bitmap into the canvas. Bug workaround. getThread().updateScreen(); diff --git a/src/com/froop/app/kegs/KegsTouch.java b/src/com/froop/app/kegs/KegsTouch.java index 7fdfd97..0467b35 100644 --- a/src/com/froop/app/kegs/KegsTouch.java +++ b/src/com/froop/app/kegs/KegsTouch.java @@ -1,6 +1,7 @@ package com.froop.app.kegs; import android.content.Context; +import android.graphics.Rect; import android.os.Handler; import android.os.Message; import android.util.Log; @@ -31,6 +32,8 @@ class KegsTouch { private static final int LONG_PRESS = 1; private static final int LONG_PRESS_TIMEOUT = ViewConfiguration.getLongPressTimeout(); + private TouchSpecialZone mSpecialZone = null; + public KegsTouch(Context context, ConcurrentLinkedQueue q) { mEventQueue = q; @@ -39,6 +42,10 @@ class KegsTouch { mTouchSlopSquare = touchSlop * touchSlop; } + public void setSpecialZone(TouchSpecialZone zone) { + mSpecialZone = zone; + } + private Handler mHandler = new Handler() { public void handleMessage(Message msg) { if (msg.what == LONG_PRESS) { @@ -120,10 +127,13 @@ class KegsTouch { } } else if (!checkPrimarySlop(event, pointerIndex)) { // It didn't move while it was down, so send a click event. - mButton1 = 1; - mEventQueue.add(new Event.MouseKegsEvent(0, 0, mButton1, 1)); - mButton1 = 0; - mEventQueue.add(new Event.MouseKegsEvent(0, 0, mButton1, 1)); + if (mSpecialZone != null && + !mSpecialZone.click(event, pointerIndex)) { + mButton1 = 1; + mEventQueue.add(new Event.MouseKegsEvent(0, 0, mButton1, 1)); + mButton1 = 0; + mEventQueue.add(new Event.MouseKegsEvent(0, 0, mButton1, 1)); + } } mPrimaryId = -1; mPrimaryPastSlop = false; diff --git a/src/com/froop/app/kegs/TouchSpecialZone.java b/src/com/froop/app/kegs/TouchSpecialZone.java new file mode 100644 index 0000000..228c871 --- /dev/null +++ b/src/com/froop/app/kegs/TouchSpecialZone.java @@ -0,0 +1,29 @@ +package com.froop.app.kegs; + +import android.graphics.Rect; +import android.util.Log; +import android.view.MotionEvent; + +class TouchSpecialZone { + // Clicks within this rect have a special handler. + private Rect mSpecialRect = null; + + public TouchSpecialZone(Rect zone) { + mSpecialRect = zone; // may be null + } + + // Override this. + public void activate() {} + + public boolean click(MotionEvent point, int index) { + if (mSpecialRect != null) { + final int x = (int)point.getX(index); + final int y = (int)point.getY(index); + if (mSpecialRect.contains(x, y)) { + activate(); + return true; + } + } + return false; + } +}