Search in sources :

Example 1 with DisplayCutout

use of android.view.DisplayCutout in project robolectric by robolectric.

the class ShadowWindowManagerImpl method getWindowInsetsFromServer.

/**
 * Re implement to avoid server call
 */
@Implementation(minSdk = R)
protected WindowInsets getWindowInsetsFromServer(WindowManager.LayoutParams attrs, Rect bounds) {
    Context context = reflector(ReflectorWindowManagerImpl.class, realObject).getContext();
    final Rect systemWindowInsets = new Rect();
    final Rect stableInsets = new Rect();
    final DisplayCutout.ParcelableWrapper displayCutout = new DisplayCutout.ParcelableWrapper();
    final InsetsState insetsState = new InsetsState();
    final boolean alwaysConsumeSystemBars = true;
    final boolean isScreenRound = context.getResources().getConfiguration().isScreenRound();
    if (getApiLevel() <= R && reflector(ViewRootImplReflector.class).getNewInsetsMode() == NEW_INSETS_MODE_FULL) {
        return ReflectionHelpers.callInstanceMethod(insetsState, "calculateInsets", ClassParameter.from(Rect.class, bounds), null, ClassParameter.from(Boolean.TYPE, isScreenRound), ClassParameter.from(Boolean.TYPE, alwaysConsumeSystemBars), ClassParameter.from(DisplayCutout.ParcelableWrapper.class, displayCutout.get()), ClassParameter.from(int.class, SOFT_INPUT_ADJUST_NOTHING), ClassParameter.from(int.class, SYSTEM_UI_FLAG_VISIBLE), null);
    } else {
        return new WindowInsets.Builder().setAlwaysConsumeSystemBars(alwaysConsumeSystemBars).setRound(isScreenRound).setSystemWindowInsets(Insets.of(systemWindowInsets)).setStableInsets(Insets.of(stableInsets)).setDisplayCutout(displayCutout.get()).build();
    }
}
Also used : Context(android.content.Context) ViewRootImplReflector(org.robolectric.shadows.ShadowViewRootImpl.ViewRootImplReflector) Rect(android.graphics.Rect) DisplayCutout(android.view.DisplayCutout) InsetsState(android.view.InsetsState) Implementation(org.robolectric.annotation.Implementation)

Example 2 with DisplayCutout

use of android.view.DisplayCutout in project UIWidget by AriesHoo.

the class NotchUtil method attachHasOfficialNotch.

/**
 * @param view
 * @return false indicates the failure to get the result
 */
@TargetApi(28)
private static boolean attachHasOfficialNotch(View view) {
    WindowInsets windowInsets = view.getRootWindowInsets();
    if (windowInsets != null) {
        DisplayCutout displayCutout = windowInsets.getDisplayCutout();
        sHasNotch = displayCutout != null;
        return true;
    } else {
        // view not attached, do nothing
        return false;
    }
}
Also used : WindowInsets(android.view.WindowInsets) DisplayCutout(android.view.DisplayCutout) TargetApi(android.annotation.TargetApi)

Example 3 with DisplayCutout

use of android.view.DisplayCutout in project var3dframe by Var3D.

the class VAndroidLauncher method getSafeAreaInsets.

public Rectangle getSafeAreaInsets() {
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
        final View decorView = getWindow().getDecorView();
        WindowInsets rootWindowInsets = null;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
            rootWindowInsets = decorView.getRootWindowInsets();
        }
        if (rootWindowInsets == null) {
            return rectangle;
        }
        DisplayCutout displayCutout = null;
        if (android.os.Build.VERSION.SDK_INT >= 28) {
            displayCutout = rootWindowInsets.getDisplayCutout();
            if (displayCutout != null) {
                rectangle.set(displayCutout.getSafeInsetLeft(), displayCutout.getSafeInsetBottom(), displayCutout.getSafeInsetRight(), displayCutout.getSafeInsetTop());
            }
        }
    }
    return rectangle;
}
Also used : WindowInsets(android.view.WindowInsets) DisplayCutout(android.view.DisplayCutout) View(android.view.View) TextView(android.widget.TextView)

Example 4 with DisplayCutout

use of android.view.DisplayCutout in project Android-skin-support by ximsfei.

the class SkinNotchUtils method attachHasOfficialNotch.

/**
 * @param view
 * @return false indicates the failure to get the result
 */
@TargetApi(28)
private static boolean attachHasOfficialNotch(View view) {
    WindowInsets windowInsets = view.getRootWindowInsets();
    if (windowInsets != null) {
        DisplayCutout displayCutout = windowInsets.getDisplayCutout();
        sHasNotch = displayCutout != null;
        return true;
    } else {
        // view not attached, do nothing
        return false;
    }
}
Also used : WindowInsets(android.view.WindowInsets) DisplayCutout(android.view.DisplayCutout) TargetApi(android.annotation.TargetApi)

Example 5 with DisplayCutout

use of android.view.DisplayCutout in project QMUI_Android by Tencent.

the class QMUINotchHelper method attachHasOfficialNotch.

/**
 * @param view
 * @return false indicates the failure to get the result
 */
@TargetApi(28)
private static boolean attachHasOfficialNotch(View view) {
    WindowInsets windowInsets = view.getRootWindowInsets();
    if (windowInsets != null) {
        DisplayCutout displayCutout = windowInsets.getDisplayCutout();
        sHasNotch = displayCutout != null;
        return true;
    } else {
        // view not attached, do nothing
        return false;
    }
}
Also used : WindowInsets(android.view.WindowInsets) DisplayCutout(android.view.DisplayCutout) TargetApi(android.annotation.TargetApi)

Aggregations

DisplayCutout (android.view.DisplayCutout)18 WindowInsets (android.view.WindowInsets)11 TargetApi (android.annotation.TargetApi)8 Rect (android.graphics.Rect)6 View (android.view.View)4 Point (android.graphics.Point)2 TextView (android.widget.TextView)2 ArrayList (java.util.ArrayList)2 Context (android.content.Context)1 IntentFilter (android.content.IntentFilter)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 InsetsState (android.view.InsetsState)1 CheckedTextView (android.widget.CheckedTextView)1 ImageView (android.widget.ImageView)1 SeekBar (android.widget.SeekBar)1 Nullable (androidx.annotation.Nullable)1 ConstraintSet (androidx.constraintlayout.widget.ConstraintSet)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 PlaybackException (com.google.android.exoplayer2.PlaybackException)1