diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-10-24 22:41:00 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-10-24 22:41:00 +0000 |
commit | daa1c44c00f3c598223639c9b80a52cf41db51ba (patch) | |
tree | e4c88a1862b157dc858abe73e52b077bf7b96948 /java/com/android/dialer/util/ViewUtil.java | |
parent | ef7338cf787301c573fde8129bf8880d7faba040 (diff) | |
parent | 938468da6f5c225ebb161a68bd949c9cf3261892 (diff) |
Merge "Rename the new bubble package name from "bubble" to "newbubble"."
Diffstat (limited to 'java/com/android/dialer/util/ViewUtil.java')
-rw-r--r-- | java/com/android/dialer/util/ViewUtil.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/java/com/android/dialer/util/ViewUtil.java b/java/com/android/dialer/util/ViewUtil.java index 81a32f985..211b3ed12 100644 --- a/java/com/android/dialer/util/ViewUtil.java +++ b/java/com/android/dialer/util/ViewUtil.java @@ -19,16 +19,19 @@ package com.android.dialer.util; import android.content.ContentResolver; import android.content.Context; import android.graphics.Paint; +import android.graphics.Point; import android.os.PowerManager; import android.provider.Settings; import android.provider.Settings.Global; import android.support.annotation.NonNull; import android.text.TextUtils; import android.util.TypedValue; +import android.view.Display; import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver.OnGlobalLayoutListener; import android.view.ViewTreeObserver.OnPreDrawListener; +import android.view.WindowManager; import android.widget.TextView; import java.util.Locale; @@ -139,4 +142,45 @@ public class ViewUtil { return Settings.Global.getFloat(contentResolver, Global.ANIMATOR_DURATION_SCALE, 1.0f) == 0 || powerManager.isPowerSaveMode(); } + + /** + * Get navigation bar height by calculating difference between app usable size and real screen + * size. Note that this won't work in multi-window mode so it's caller's responsibility to check + * if the app is in multi-window mode before using this. + * + * @param context Context + * @return Navigation bar height + */ + public static int getNavigationBarHeight(Context context) { + WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); + Display display = windowManager.getDefaultDisplay(); + Point appUsableSize = getAppUsableScreenSize(display); + Point realScreenSize = getRealScreenSize(display); + + // Navigation bar on the right. + if (appUsableSize.x < realScreenSize.x) { + return appUsableSize.y; + } + + // Navigation bar at the bottom. + if (appUsableSize.y < realScreenSize.y) { + return realScreenSize.y - appUsableSize.y; + } + + // Navigation bar is not present. + return 0; + } + + private static Point getAppUsableScreenSize(Display display) { + Point size = new Point(); + display.getSize(size); + return size; + } + + private static Point getRealScreenSize(Display display) { + Point size = new Point(); + display.getRealSize(size); + + return size; + } } |