Java Code Examples for android.view.ViewGroup#getSystemUiVisibility()

The following examples show how to use android.view.ViewGroup#getSystemUiVisibility() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BarUtils.java    From Android-utils with Apache License 2.0 6 votes vote down vote up
/**
 * Return whether the navigation bar visible.
 * <p>Call it in onWindowFocusChanged will get right result.</p>
 *
 * @param window The window.
 * @return {@code true}: yes<br>{@code false}: no
 */
public static boolean isNavBarVisible(@NonNull final Window window) {
    boolean isVisible = false;
    ViewGroup decorView = (ViewGroup) window.getDecorView();
    for (int i = 0, count = decorView.getChildCount(); i < count; i++) {
        final View child = decorView.getChildAt(i);
        final int id = child.getId();
        if (id != View.NO_ID) {
            String resourceEntryName = UtilsApp.getApp()
                    .getResources()
                    .getResourceEntryName(id);
            if ("navigationBarBackground".equals(resourceEntryName)
                    && child.getVisibility() == View.VISIBLE) {
                isVisible = true;
                break;
            }
        }
    }
    if (isVisible) {
        int visibility = decorView.getSystemUiVisibility();
        isVisible = (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
    }
    return isVisible;
}
 
Example 2
Source File: BarUtils.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
/**
 * 判断 Navigation Bar 是否可见
 * @param window {@link Window}
 * @return {@code true} yes, {@code false} no
 */
public static boolean isNavBarVisible(final Window window) {
    if (window != null) {
        boolean isVisible = false;
        ViewGroup decorView = (ViewGroup) window.getDecorView();
        for (int i = 0, count = decorView.getChildCount(); i < count; i++) {
            final View child = decorView.getChildAt(i);
            final int id = child.getId();
            if (id != View.NO_ID) {
                String resourceEntryName = Resources.getSystem().getResourceEntryName(id);
                if ("navigationBarBackground".equals(resourceEntryName)
                        && child.getVisibility() == View.VISIBLE) {
                    isVisible = true;
                    break;
                }
            }
        }
        if (isVisible) {
            int visibility = decorView.getSystemUiVisibility();
            isVisible = (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
        }
        return isVisible;
    }
    return false;
}
 
Example 3
Source File: BarUtils.java    From AndroidUtilCode with Apache License 2.0 6 votes vote down vote up
/**
 * Return whether the navigation bar visible.
 * <p>Call it in onWindowFocusChanged will get right result.</p>
 *
 * @param window The window.
 * @return {@code true}: yes<br>{@code false}: no
 */
public static boolean isNavBarVisible(@NonNull final Window window) {
    boolean isVisible = false;
    ViewGroup decorView = (ViewGroup) window.getDecorView();
    for (int i = 0, count = decorView.getChildCount(); i < count; i++) {
        final View child = decorView.getChildAt(i);
        final int id = child.getId();
        if (id != View.NO_ID) {
            String resourceEntryName = getResNameById(id);
            if ("navigationBarBackground".equals(resourceEntryName)
                    && child.getVisibility() == View.VISIBLE) {
                isVisible = true;
                break;
            }
        }
    }
    if (isVisible) {
        int visibility = decorView.getSystemUiVisibility();
        isVisible = (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
    }
    return isVisible;
}
 
Example 4
Source File: VideoView.java    From DKVideoPlayer with Apache License 2.0 5 votes vote down vote up
private void hideSysBar(ViewGroup decorView) {
    int uiOptions = decorView.getSystemUiVisibility();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        uiOptions |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        uiOptions |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
    }
    decorView.setSystemUiVisibility(uiOptions);
    getActivity().getWindow().setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
 
Example 5
Source File: VideoView.java    From DKVideoPlayer with Apache License 2.0 5 votes vote down vote up
private void showSysBar(ViewGroup decorView) {
    int uiOptions = decorView.getSystemUiVisibility();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        uiOptions &= ~View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        uiOptions &= ~View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
    }
    decorView.setSystemUiVisibility(uiOptions);
    getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}