OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser; |
| 6 |
| 7 import android.annotation.TargetApi; |
| 8 import android.content.Context; |
| 9 import android.graphics.Rect; |
| 10 import android.os.Build; |
| 11 import android.util.AttributeSet; |
| 12 import android.view.WindowInsets; |
| 13 import android.widget.FrameLayout; |
| 14 |
| 15 /** |
| 16 * The purpose of this view is to consume the insets (OSK resizes, status bar). |
| 17 * It stores the value of the insets in ContentViewCore so that size of things |
| 18 * like the OSK can be known. |
| 19 */ |
| 20 public class InsetConsumerView extends FrameLayout { |
| 21 |
| 22 private Rect mWindowInsets; |
| 23 |
| 24 /** |
| 25 * Creates an {@link InsetConsumerView}. |
| 26 * |
| 27 * @param context The Context to create this {@link InsetConsumerView} in. |
| 28 */ |
| 29 public InsetConsumerView(Context context) { |
| 30 super(context); |
| 31 mWindowInsets = new Rect(); |
| 32 } |
| 33 |
| 34 /** |
| 35 * Creates an {@link InsetConsumerView}. |
| 36 * |
| 37 * @param context The Context to create this {@link InsetConsumerView} in. |
| 38 * @param attrs The AttributeSet used to create this |
| 39 * {@link InsetConsumerView}. |
| 40 */ |
| 41 public InsetConsumerView(Context context, AttributeSet attrs) { |
| 42 super(context, attrs); |
| 43 mWindowInsets = new Rect(); |
| 44 } |
| 45 |
| 46 /** |
| 47 * Returns the left {@link WindowInsets} in pixels. |
| 48 * |
| 49 * @return The left system window inset. |
| 50 */ |
| 51 public int getSystemWindowInsetsLeft() { |
| 52 return mWindowInsets.left; |
| 53 } |
| 54 |
| 55 /** |
| 56 * Returns the top {@link WindowInsets} in pixels. |
| 57 * |
| 58 * @return The top system window inset. |
| 59 */ |
| 60 public int getSystemWindowInsetsTop() { |
| 61 return mWindowInsets.top; |
| 62 } |
| 63 |
| 64 /** |
| 65 * Returns the right {@link WindowInsets} in pixels. |
| 66 * |
| 67 * @return The right system window inset. |
| 68 */ |
| 69 public int getSystemWindowInsetsRight() { |
| 70 return mWindowInsets.right; |
| 71 } |
| 72 |
| 73 /** |
| 74 * Returns the bottom {@link WindowInsets} in pixels. |
| 75 * |
| 76 * @return The bottom system window inset. |
| 77 */ |
| 78 public int getSystemWindowInsetsBottom() { |
| 79 return mWindowInsets.bottom; |
| 80 } |
| 81 |
| 82 @SuppressWarnings("deprecation") |
| 83 @Override |
| 84 protected boolean fitSystemWindows(Rect insets) { |
| 85 // For Lollipop and above, onApplyWindowInsets will set the insets. |
| 86 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { |
| 87 mWindowInsets.set(insets.left, insets.top, insets.right, insets.bott
om); |
| 88 } |
| 89 return super.fitSystemWindows(insets); |
| 90 } |
| 91 |
| 92 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
| 93 @Override |
| 94 public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
| 95 mWindowInsets.set(insets.getSystemWindowInsetLeft(), insets.getSystemWin
dowInsetTop(), |
| 96 insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetB
ottom()); |
| 97 return super.onApplyWindowInsets(insets); |
| 98 } |
| 99 } |
OLD | NEW |