From 8d8653ab21f872e1117b99d08005d5ade5f9843c Mon Sep 17 00:00:00 2001 From: James Sanford Date: Sun, 28 Oct 2012 00:27:30 -0700 Subject: [PATCH] Update ActionBar visibility immediately. --- src/com/froop/app/kegs/BitmapSize.java | 15 ++++++++++++++ src/com/froop/app/kegs/KegsMain.java | 27 +++++++++----------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/com/froop/app/kegs/BitmapSize.java b/src/com/froop/app/kegs/BitmapSize.java index 1bb1ccf..402176c 100644 --- a/src/com/froop/app/kegs/BitmapSize.java +++ b/src/com/froop/app/kegs/BitmapSize.java @@ -1,5 +1,6 @@ package com.froop.app.kegs; +import android.content.Context; import android.graphics.Rect; import android.util.DisplayMetrics; import android.util.Log; @@ -29,6 +30,20 @@ class BitmapSize { calculateScale(width, height); } + + // Next method provides a rough estimate based on the total display size. + public static BitmapSize quick(Context context) { + final DisplayMetrics metrics = context.getResources().getDisplayMetrics(); + int width = metrics.widthPixels; + int height = metrics.heightPixels; + if (android.os.Build.VERSION.SDK_INT >= 11) { + // NOTE: 48 is a guess at the System Bar obstruction. + // These are 'visible insets' into the display from the window manager. + height -= 48; + } + return new BitmapSize(width, height, metrics); + } + private boolean isLargeScreen(DisplayMetrics display) { float a_side = (display.widthPixels / display.xdpi); float b_side = (display.heightPixels / display.ydpi); diff --git a/src/com/froop/app/kegs/KegsMain.java b/src/com/froop/app/kegs/KegsMain.java index e82d791..07daf9c 100644 --- a/src/com/froop/app/kegs/KegsMain.java +++ b/src/com/froop/app/kegs/KegsMain.java @@ -238,14 +238,10 @@ public class KegsMain extends SherlockFragmentActivity implements KegsKeyboard.S private void updateActionBar(boolean showActionBar) { final ActionBar actionBar = getSupportActionBar(); - if (showActionBar) { - if (actionBar != null && !actionBar.isShowing()) { - actionBar.show(); - } - } else { - if (actionBar != null && actionBar.isShowing()) { - actionBar.hide(); - } + if (actionBar != null && showActionBar) { + actionBar.show(); + } else if (actionBar != null && !showActionBar) { + actionBar.hide(); } } @@ -279,16 +275,9 @@ public class KegsMain extends SherlockFragmentActivity implements KegsKeyboard.S // Fire off a guess at a new size during this request, // it makes the animation transition look better. - int width = getResources().getDisplayMetrics().widthPixels; - int height = getResources().getDisplayMetrics().heightPixels; - if (android.os.Build.VERSION.SDK_INT >= 11) { - // NOTE: 48 is a guess at the System Bar obstruction. - // These are 'visible insets' into the display from the window manager. - height -= 48; - } - final BitmapSize bitmapSize = new BitmapSize(width, height, getResources().getDisplayMetrics()); - updateActionBar(bitmapSize.showActionBar()); - mKegsView.updateScreenSize(bitmapSize); + final BitmapSize quickSize = BitmapSize.quick(this); + updateActionBar(quickSize.showActionBar()); + mKegsView.updateScreenSize(quickSize); getThread().updateScreen(); } @@ -364,6 +353,8 @@ public class KegsMain extends SherlockFragmentActivity implements KegsKeyboard.S super.onCreate(savedInstanceState); setContentView(R.layout.main); + updateActionBar(BitmapSize.quick(this).showActionBar()); + mKegsView = (KegsViewGL)findViewById(R.id.kegsview); mConfigFile = new ConfigFile(this);