Show action bar on large screens.

This commit is contained in:
James Sanford 2012-10-23 17:11:51 -07:00
parent 593030f327
commit 0a335a265b
2 changed files with 23 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package com.froop.app.kegs;
import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.util.Log;
class BitmapSize {
@ -8,27 +9,45 @@ class BitmapSize {
public static final int A2Width = 640 + 32 + 32; // kegs defcomm.h
public static final int A2Height = 400 + 32 + 30; // kegs defcomm.h
}
private static final float LARGE_SCREEN_INCHES = 9.0f;
private int mWidth = 0;
private int mHeight = 0;
private boolean mLargeScreen = false;
private boolean mScaled = false;
private boolean mCropped = false;
private float mScaleFactorX = 1.0f;
private float mScaleFactorY = 1.0f;
public BitmapSize(int width, int height) {
public BitmapSize(int width, int height, DisplayMetrics display) {
mWidth = width;
mHeight = height;
if (display != null) {
mLargeScreen = isLargeScreen(display);
}
calculateScale(width, height);
}
private boolean isLargeScreen(DisplayMetrics display) {
float a_side = (display.widthPixels / display.xdpi);
float b_side = (display.heightPixels / display.ydpi);
float a_squared = a_side * a_side;
float b_squared = b_side * b_side;
float diagonal = LARGE_SCREEN_INCHES * LARGE_SCREEN_INCHES;
return (a_squared + b_squared > diagonal);
}
public boolean showActionBar() {
if (mWidth < mHeight) {
// portrait mode
return true;
} else if (mLargeScreen) {
// 9 inches or more
return true;
} else {
// TODO FIXME: also if the screen is BIG, return true.
return false;
}
}

View File

@ -258,7 +258,7 @@ public class KegsMain extends Activity implements KegsKeyboard.StickyReset, Asse
// so bail out here if the time doesn't match the last message.
return;
}
final BitmapSize bitmapSize = new BitmapSize(width, height);
final BitmapSize bitmapSize = new BitmapSize(width, height, getResources().getDisplayMetrics());
updateActionBar(bitmapSize.showActionBar());
@ -280,7 +280,7 @@ public class KegsMain extends Activity implements KegsKeyboard.StickyReset, Asse
// These are 'visible insets' into the display from the window manager.
height -= 48;
}
final BitmapSize bitmapSize = new BitmapSize(width, height);
final BitmapSize bitmapSize = new BitmapSize(width, height, getResources().getDisplayMetrics());
updateActionBar(bitmapSize.showActionBar());
mKegsView.updateScreenSize(bitmapSize);
getThread().updateScreen();