| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.policy; |
| 18 |
|
| 19 |
import android.content.Context; |
| 20 |
import android.content.res.Resources; |
| 21 |
import android.graphics.Insets; |
| 22 |
import android.util.RotationUtils; |
| 23 |
import android.view.DisplayCutout; |
| 24 |
import android.view.Surface; |
| 25 |
|
| 26 |
import com.android.internal.R; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public final class SystemBarUtils { |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public static int getStatusBarHeight(Context context) { |
| 39 |
return getStatusBarHeight(context.getResources(), context.getDisplay().getCutout()); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public static int getStatusBarHeight(Resources res, DisplayCutout cutout) { |
| 46 |
final int defaultSize = res.getDimensionPixelSize(R.dimen.status_bar_height_default); |
| 47 |
final int safeInsetTop = cutout == null ? 0 : cutout.getSafeInsetTop(); |
| 48 |
final int waterfallInsetTop = cutout == null ? 0 : cutout.getWaterfallInsets().top; |
| 49 |
|
| 50 |
|
| 51 |
return Math.max(safeInsetTop, defaultSize + waterfallInsetTop); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
public static int getStatusBarHeightForRotation( |
| 58 |
Context context, @Surface.Rotation int targetRot) { |
| 59 |
final int rotation = context.getDisplay().getRotation(); |
| 60 |
final DisplayCutout cutout = context.getDisplay().getCutout(); |
| 61 |
|
| 62 |
Insets insets = cutout == null ? Insets.NONE : Insets.of(cutout.getSafeInsets()); |
| 63 |
Insets waterfallInsets = cutout == null ? Insets.NONE : cutout.getWaterfallInsets(); |
| 64 |
|
| 65 |
if (rotation != targetRot) { |
| 66 |
if (!insets.equals(Insets.NONE)) { |
| 67 |
insets = RotationUtils.rotateInsets( |
| 68 |
insets, RotationUtils.deltaRotation(rotation, targetRot)); |
| 69 |
} |
| 70 |
if (!waterfallInsets.equals(Insets.NONE)) { |
| 71 |
waterfallInsets = RotationUtils.rotateInsets( |
| 72 |
waterfallInsets, RotationUtils.deltaRotation(rotation, targetRot)); |
| 73 |
} |
| 74 |
} |
| 75 |
final int defaultSize = |
| 76 |
context.getResources().getDimensionPixelSize(R.dimen.status_bar_height_default); |
| 77 |
|
| 78 |
|
| 79 |
return Math.max(insets.top, defaultSize + waterfallInsets.top); |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public static int getQuickQsOffsetHeight(Context context) { |
| 88 |
final int defaultSize = context.getResources().getDimensionPixelSize( |
| 89 |
R.dimen.quick_qs_offset_height); |
| 90 |
final int statusBarHeight = getStatusBarHeight(context); |
| 91 |
|
| 92 |
return Math.max(defaultSize, statusBarHeight); |
| 93 |
} |
| 94 |
} |