From 2b022420a62eb3fb39a6c1783a3dd65ab701eed0 Mon Sep 17 00:00:00 2001 From: d34d Date: Thu, 19 Mar 2015 09:35:18 -0700 Subject: Properly pad layouts when on screen nav is used This patch checks if the device has no hardware keys or if the user has enabled on screen navigation even though the device has hardware keys. Change-Id: Ie93280a275735567390e2cdc34a82d4de63a8450 --- src/com/cyngn/theme/util/Utils.java | 18 ++++++++++++++++-- src/com/cyngn/theme/widget/NavBarSpace.java | 11 ++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) (limited to 'src/com') diff --git a/src/com/cyngn/theme/util/Utils.java b/src/com/cyngn/theme/util/Utils.java index cbcbe4a..3fe8c63 100644 --- a/src/com/cyngn/theme/util/Utils.java +++ b/src/com/cyngn/theme/util/Utils.java @@ -21,12 +21,15 @@ import android.graphics.BitmapFactory; import android.graphics.BitmapRegionDecoder; import android.graphics.Point; import android.graphics.Rect; +import android.os.RemoteException; +import android.provider.Settings; import android.provider.ThemesContract; import android.util.Log; import android.util.TypedValue; -import android.view.ViewConfiguration; +import android.view.IWindowManager; import android.view.WindowManager; +import android.view.WindowManagerGlobal; import com.cyngn.theme.chooser.ChooserActivity; import java.io.File; @@ -244,7 +247,18 @@ public class Utils { } public static boolean hasNavigationBar(Context context) { - return !ViewConfiguration.get(context).hasPermanentMenuKey(); + boolean needsNavigationBar = false; + try { + IWindowManager wm = WindowManagerGlobal.getWindowManagerService(); + needsNavigationBar = wm.needsNavigationBar(); + } catch (RemoteException e) { + } + // Need to also check for devices with hardware keys where the user has chosen to use + // the on screen navigation bar + needsNavigationBar = needsNavigationBar || + Settings.Secure.getInt(context.getContentResolver(), + Settings.Secure.DEV_FORCE_SHOW_NAVBAR, 0) == 1; + return needsNavigationBar; } public static Bitmap loadBitmapBlob(Cursor cursor, int columnIdx) { diff --git a/src/com/cyngn/theme/widget/NavBarSpace.java b/src/com/cyngn/theme/widget/NavBarSpace.java index 71dce4d..993e9cf 100644 --- a/src/com/cyngn/theme/widget/NavBarSpace.java +++ b/src/com/cyngn/theme/widget/NavBarSpace.java @@ -28,11 +28,12 @@ public class NavBarSpace extends View { } @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - if (!Utils.hasNavigationBar(mContext)) { - int width = MeasureSpec.getSize(widthMeasureSpec); - setMeasuredDimension(width, 0); + protected void onFinishInflate() { + super.onFinishInflate(); + if (!Utils.hasNavigationBar(getContext())) { + this.setVisibility(View.GONE); + } else { + this.setVisibility(View.VISIBLE); } } } -- cgit v1.2.3