Java Code Examples for android.view.View#setOnApplyWindowInsetsListener()
The following examples show how to use
android.view.View#setOnApplyWindowInsetsListener() .
These examples are extracted from open source projects.
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 Project: react-native-modal-translucent File: TranslucentModalHostView.java License: MIT License | 6 votes |
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); } }
Example 2
Source Project: AndroidNavigation File: AppUtils.java License: MIT License | 6 votes |
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()); } }
Example 3
Source Project: DKVideoPlayer File: BaseActivity.java License: Apache License 2.0 | 6 votes |
/** * 把状态栏设成透明 */ 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)); } }
Example 4
Source Project: ETSMobile-Android2 File: ShapeWear.java License: Apache License 2.0 | 6 votes |
/** * 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; } }); }
Example 5
Source Project: google-io-2014 File: DetailActivity.java License: Apache License 2.0 | 6 votes |
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(); } }); }
Example 6
Source Project: animation-samples File: ViewUtils.java License: Apache License 2.0 | 5 votes |
/** * 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(); }
Example 7
Source Project: focus-android File: StatusBarUtils.java License: Mozilla Public License 2.0 | 5 votes |
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; } }); }
Example 8
Source Project: zephyr File: NotificationActivity.java License: MIT License | 5 votes |
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; }); }
Example 9
Source Project: zephyr File: MainActivity.java License: MIT License | 5 votes |
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; }); }
Example 10
Source Project: zephyr File: LicensesActivity.java License: MIT License | 5 votes |
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(); }); }
Example 11
Source Project: AndroidWear-OpenWear File: ShapeDetector.java License: MIT License | 5 votes |
/** * 检测手表端设备屏幕形状 * * @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; } }); }
Example 12
Source Project: 920-text-editor-v2 File: DrawerLayoutCompatApi21.java License: Apache License 2.0 | 5 votes |
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); } }
Example 13
Source Project: WearViewStub File: ShapeWear.java License: Apache License 2.0 | 5 votes |
/** * 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(); } }
Example 14
Source Project: Dashchan File: DrawerLayout.java License: Apache License 2.0 | 5 votes |
@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); } }
Example 15
Source Project: adt-leanback-support File: DrawerLayoutCompatApi21.java License: Apache License 2.0 | 5 votes |
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); } }
Example 16
Source Project: debugdrawer File: DrawerLayoutCompatApi21.java License: Apache License 2.0 | 5 votes |
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); } }
Example 17
Source Project: u2020 File: DrawerLayoutCompatApi21.java License: Apache License 2.0 | 5 votes |
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); } }