Add some safety checks around action bar update.

This commit is contained in:
James Sanford 2012-10-03 21:51:49 -07:00
parent ee2814b689
commit f557787e81
2 changed files with 21 additions and 12 deletions

View File

@ -27,9 +27,8 @@ class BitmapSize {
if (mScaleFactorY != 1.0f && mScaleFactorX != mScaleFactorY) {
return false;
} else if (mHeight < getViewHeight()) {
// TODO: FIXME: This could possibly cause the action bar to turn on and off repeatedly, so be careful about when saying it's safe to turn on or off.
// One way would be if we have turned it off for a certain height,
// and a new height is within 20% of that height, keep it off.
// However, beware that disabling the action bar may increase
// the space enough to think that we should reenable it.
return false;
} else {
return true;

View File

@ -38,6 +38,7 @@ public class KegsMain extends Activity implements KegsKeyboard.StickyReset {
private PopupMenu mSettingsMenu;
private boolean mModeMouse = true;
private int mLastActionBar = 0; // window height at last ActionBar change.
private View.OnClickListener mButtonClick = new View.OnClickListener() {
public void onClick(View v) {
@ -194,6 +195,19 @@ public class KegsMain extends Activity implements KegsKeyboard.StickyReset {
}
}
private void updateActionBar(boolean showActionBar) {
final ActionBar actionBar = getActionBar();
if (showActionBar) {
if (actionBar != null && !actionBar.isShowing()) {
actionBar.show();
}
} else {
if (actionBar != null && actionBar.isShowing()) {
actionBar.hide();
}
}
}
private void setScreenSize(boolean quick) {
int width;
int height;
@ -216,15 +230,11 @@ public class KegsMain extends Activity implements KegsKeyboard.StickyReset {
mKegsView.updateScreenSize(bitmapSize);
final ActionBar actionBar = getActionBar();
if (bitmapSize.showActionBar()) {
if (actionBar != null && !actionBar.isShowing()) {
actionBar.show();
}
} else {
if (actionBar != null && actionBar.isShowing()) {
actionBar.hide();
}
// Only change action bar if the window height is significantly
// different from the last time we changed the action bar.
if (height < (mLastActionBar * 0.85) || height > (mLastActionBar * 1.15)) {
mLastActionBar = height;
updateActionBar(bitmapSize.showActionBar());
}
// Force another redraw of the bitmap into the canvas. Bug workaround.