android.view.View#setOnApplyWindowInsetsListener ( )源码实例Demo

下面列出了android.view.View#setOnApplyWindowInsetsListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

public static void setStatusBarTranslucent(Window window, boolean translucent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        View decorView = window.getDecorView();
        if (translucent) {
            decorView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
                @TargetApi(Build.VERSION_CODES.LOLLIPOP)
                @Override
                public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                    WindowInsets defaultInsets = v.onApplyWindowInsets(insets);
                    return defaultInsets.replaceSystemWindowInsets(
                            defaultInsets.getSystemWindowInsetLeft(),
                            0,
                            defaultInsets.getSystemWindowInsetRight(),
                            defaultInsets.getSystemWindowInsetBottom());
                }
            });
        } else {
            decorView.setOnApplyWindowInsetsListener(null);
        }
        ViewCompat.requestApplyInsets(decorView);
    }
}
 
源代码2 项目: DKVideoPlayer   文件: BaseActivity.java
/**
 * 把状态栏设成透明
 */
protected void setStatusBarTransparent() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        View decorView = getWindow().getDecorView();
        decorView.setOnApplyWindowInsetsListener((v, insets) -> {
            WindowInsets defaultInsets = v.onApplyWindowInsets(insets);
            return defaultInsets.replaceSystemWindowInsets(
                    defaultInsets.getSystemWindowInsetLeft(),
                    0,
                    defaultInsets.getSystemWindowInsetRight(),
                    defaultInsets.getSystemWindowInsetBottom());
        });
        ViewCompat.requestApplyInsets(decorView);
        getWindow().setStatusBarColor(ContextCompat.getColor(this, android.R.color.transparent));
    }
}
 
源代码3 项目: ETSMobile-Android2   文件: ShapeWear.java
/**
 * Initialized to determine screen shape
 *
 * @param view
 */
private static void initShapeDetection(View view) {
    view.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
            if (insets.isRound()) {
                shape = ScreenShape.ROUND;
                if (screenWidthPX == 320 && screenHeightPX == 290) {
                    shape = ScreenShape.MOTO_ROUND;
                }
            } else {
                shape = ScreenShape.RECTANGLE;
            }
            if (onShapeChangeListener != null) {
                onShapeChangeListener.shapeDetected(getShape());
            }
            return insets;
        }
    });
}
 
源代码4 项目: google-io-2014   文件: DetailActivity.java
private void applySystemWindowsBottomInset(int container) {
    View containerView = findViewById(container);
    containerView.setFitsSystemWindows(true);
    containerView.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
            DisplayMetrics metrics = getResources().getDisplayMetrics();
            if (metrics.widthPixels < metrics.heightPixels) {
                view.setPadding(0, 0, 0, windowInsets.getSystemWindowInsetBottom());
            } else {
                view.setPadding(0, 0, windowInsets.getSystemWindowInsetRight(), 0);
            }
            return windowInsets.consumeSystemWindowInsets();
        }
    });
}
 
源代码5 项目: animation-samples   文件: ViewUtils.java
/**
 * Applies top window insets for a view.
 *
 * @param view The view to apply insets for.
 */
public static void applyTopWindowInsetsForView(@NonNull final View view) {
    view.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
            v.setPadding(v.getPaddingLeft(), insets.getSystemWindowInsetTop()
                    + v.getPaddingTop(), v.getPaddingRight(), v.getPaddingBottom());
            return insets;
        }
    });
    view.requestApplyInsets();
}
 
源代码6 项目: AndroidNavigation   文件: AppUtils.java
public static void setStatusBarTranslucent(Window window, boolean translucent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setRenderContentInShortEdgeCutoutAreas(window, translucent);

        View decorView = window.getDecorView();
        if (translucent) {
            decorView.setOnApplyWindowInsetsListener((v, insets) -> {
                WindowInsets defaultInsets = v.onApplyWindowInsets(insets);
                return defaultInsets.replaceSystemWindowInsets(
                        defaultInsets.getSystemWindowInsetLeft(),
                        0,
                        defaultInsets.getSystemWindowInsetRight(),
                        defaultInsets.getSystemWindowInsetBottom());
            });
        } else {
            decorView.setOnApplyWindowInsetsListener(null);
        }

        ViewCompat.requestApplyInsets(decorView);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (translucent) {
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        } else {
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        ViewCompat.requestApplyInsets(window.getDecorView());
    }
}
 
源代码7 项目: focus-android   文件: StatusBarUtils.java
public static void getStatusBarHeight(final View view, final StatusBarHeightListener listener) {
    if (STATUS_BAR_HEIGHT > 0) {
        listener.onStatusBarHeightFetched(STATUS_BAR_HEIGHT);
    }

    view.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
            STATUS_BAR_HEIGHT = insets.getSystemWindowInsetTop();
            listener.onStatusBarHeightFetched(STATUS_BAR_HEIGHT);
            return insets;
        }
    });
}
 
源代码8 项目: zephyr   文件: NotificationActivity.java
private void setupEdgeToEdgeLayout() {
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
    decorView.setOnApplyWindowInsetsListener((v, insets) -> {
        AppBarLayout.LayoutParams toolbarLayoutParams = new AppBarLayout.LayoutParams(mToolbar.getLayoutParams());
        toolbarLayoutParams.setMargins(0, insets.getSystemWindowInsetTop(), 0, 0);
        mToolbar.setLayoutParams(toolbarLayoutParams);
        return insets;
    });
}
 
源代码9 项目: zephyr   文件: MainActivity.java
private void setupEdgeToEdgeLayout() {
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
    decorView.setOnApplyWindowInsetsListener((v, insets) -> {
        CoordinatorLayout.LayoutParams mainFragmentLayoutParams = new CoordinatorLayout.LayoutParams(mMainFragment.getLayoutParams());
        mainFragmentLayoutParams.setMargins(0, insets.getSystemWindowInsetTop(), 0, 0);
        mMainFragment.setLayoutParams(mainFragmentLayoutParams);
        return insets;
    });
}
 
源代码10 项目: zephyr   文件: LicensesActivity.java
private void setupEdgeToEdgeLayout() {
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
    decorView.setOnApplyWindowInsetsListener((v, insets) -> {
        mToolbar.setPadding(0, insets.getSystemWindowInsetTop(), 0, 0);
        return insets.consumeSystemWindowInsets();
    });
}
 
源代码11 项目: AndroidWear-OpenWear   文件: ShapeDetector.java
/**
 * 检测手表端设备屏幕形状
 *
 * @param view     用于检测的view
 * @param callback 检测结果的回调
 */
@TargetApi(20)
public static void detectShapeOnWatch(View view, final ShapeDetectCallback callback) {

    if (callback != null && shape != SHAPE_UNKNOWN) {
        callback.onShapeDetected(shape);

        return;
    }

    if (Build.VERSION.SDK_INT < 20) {
        if (callback != null) {
            callback.onShapeDetected(SHAPE_SQUARE);
        }
        return;
    }

    // Added in API level 20
    view.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {

        @Override
        public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {

            if (insets.isRound()) {
                shape = SHAPE_ROUND;

            } else {
                shape = SHAPE_SQUARE;
            }

            if (callback != null) {
                callback.onShapeDetected(shape);
            }
            return insets;
        }
    });
}
 
public static void configureApplyInsets(View drawerLayout) {
    if (drawerLayout instanceof DrawerLayoutImpl) {
        drawerLayout.setOnApplyWindowInsetsListener(new InsetsListener());
        drawerLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }
}
 
源代码13 项目: WearViewStub   文件: ShapeWear.java
/**
 * Initialized to determine screen shape
 * @param view
 */
private static void initShapeDetection(View view){
    if(!setOnApplyWindowInsetsListenerCalled) {
        setOnApplyWindowInsetsListenerCalled = true;
        view.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
            @Override
                public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
                if (insets.isRound()) {
                    shape = ScreenShape.ROUND;
                    if (screenWidthPX == 320 && screenHeightPX == 290) {
                        shape = ScreenShape.MOTO_ROUND;
                    }
                } else {
                    shape = ScreenShape.RECTANGLE;
                }
                if (onShapeChangeListeners != null && !onShapeChangeListeners.isEmpty()) {
                    synchronized (onShapeChangeListeners) {
                        for (OnShapeChangeListener listener : onShapeChangeListeners)
                            listener.shapeDetected(getShape());
                    }
                }
                return insets;
            }
        });
        view.requestApplyInsets();
    }
}
 
源代码14 项目: Dashchan   文件: DrawerLayout.java
@Override
public void configureApplyInsets(View drawerLayout) {
	if (drawerLayout instanceof DrawerLayout) {
		drawerLayout.setOnApplyWindowInsetsListener(new InsetsListener());
		drawerLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
				| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
	}
}
 
public static void configureApplyInsets(View drawerLayout) {
    if (drawerLayout instanceof DrawerLayoutImpl) {
        drawerLayout.setOnApplyWindowInsetsListener(new InsetsListener());
        drawerLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }
}
 
源代码16 项目: debugdrawer   文件: DrawerLayoutCompatApi21.java
public static void configureApplyInsets(View drawerLayout) {
	if (drawerLayout instanceof DrawerLayoutImpl) {
		drawerLayout.setOnApplyWindowInsetsListener(new InsetsListener());
		drawerLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
				| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
	}
}
 
源代码17 项目: u2020   文件: DrawerLayoutCompatApi21.java
public static void configureApplyInsets(View drawerLayout) {
  if (drawerLayout instanceof DrawerLayoutImpl) {
    drawerLayout.setOnApplyWindowInsetsListener(new InsetsListener());
    drawerLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
  }
}
 
 方法所在类
 同类方法