mirror of
https://github.com/jamessanford/kegs.git
synced 2024-09-27 08:54:33 +00:00
Support for special click area to toggle ActionBar.
This commit is contained in:
parent
d12e3a8d0c
commit
54108c346f
@ -67,6 +67,14 @@ class BitmapSize {
|
||||
}
|
||||
}
|
||||
|
||||
public int getScreenWidth() {
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
public int getScreenHeight() {
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
public int getViewWidth() {
|
||||
return (int)(Const.A2Width * mScaleFactorX);
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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,11 +127,14 @@ class KegsTouch {
|
||||
}
|
||||
} else if (!checkPrimarySlop(event, pointerIndex)) {
|
||||
// It didn't move while it was down, so send a click event.
|
||||
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;
|
||||
mPrimaryLongPress = false;
|
||||
|
29
src/com/froop/app/kegs/TouchSpecialZone.java
Normal file
29
src/com/froop/app/kegs/TouchSpecialZone.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user