Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/InsetConsumerView.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/InsetConsumerView.java b/chrome/android/java/src/org/chromium/chrome/browser/InsetConsumerView.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..498a47824cfcd0355dd54d74b4d41d4b81d15fa3 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/InsetConsumerView.java |
| @@ -0,0 +1,111 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser; |
| + |
| +import android.annotation.TargetApi; |
| +import android.content.Context; |
| +import android.graphics.Rect; |
| +import android.os.Build; |
| +import android.view.View; |
| +import android.view.WindowInsets; |
| + |
| +/** |
| + * The purpose of this view is to store the insets (OSK resizes, status bar) for |
|
Ted C
2016/03/14 22:53:07
line length for comments in java is 100 (applies e
ymalik
2016/03/15 16:23:26
Done. Update other comments.
|
| + * later use before they are consumed by the the children views in the view |
|
Ted C
2016/03/14 22:53:07
comment needs to be updated
ymalik
2016/03/15 16:23:26
Done.
|
| + * hierarchy. |
| + */ |
| +public class InsetConsumerView extends View { |
| + |
| + protected final Rect mWindowInsets; |
| + |
| + /** |
| + * Constructs a new {@link InsetConsumerView} for the appropriate Android |
| + * version. |
| + * @param context The Context the view is running in, through which it can |
| + * access the current theme, resources, etc. |
|
Ted C
2016/03/14 22:53:07
align with "The Context..." above.
ymalik
2016/03/15 16:23:26
Done.
|
| + * @return an instance of a InsetConsumerView. |
| + */ |
| + public static InsetConsumerView create(Context context) { |
| + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { |
| + return new InsetConsumerView(context); |
| + } |
| + return new InsetConsumerViewApi21(context); |
| + } |
| + |
| + /** |
| + * Creates an instance of {@link InsetConsumerView}. |
| + * @param context The Context to create this {@link InsetConsumerView} in. |
| + */ |
| + public InsetConsumerView(Context context) { |
| + super(context); |
| + setVisibility(INVISIBLE); |
| + mWindowInsets = new Rect(); |
| + } |
| + |
| + /** |
| + * Returns the left {@link WindowInsets} in pixels. |
| + * @return The left system window inset. |
|
Ted C
2016/03/14 22:53:07
for each of these, you can drop the @return. For
ymalik
2016/03/15 16:23:26
Done.
|
| + */ |
| + public int getSystemWindowInsetsLeft() { |
| + return mWindowInsets.left; |
| + } |
| + |
| + /** |
| + * Returns the top {@link WindowInsets} in pixels. |
| + * @return The top system window inset. |
| + */ |
| + public int getSystemWindowInsetsTop() { |
| + return mWindowInsets.top; |
| + } |
| + |
| + /** |
| + * Returns the right {@link WindowInsets} in pixels. |
| + * @return The right system window inset. |
| + */ |
| + public int getSystemWindowInsetsRight() { |
| + return mWindowInsets.right; |
| + } |
| + |
| + /** |
| + * Returns the bottom {@link WindowInsets} in pixels. |
| + * @return The bottom system window inset. |
| + */ |
| + public int getSystemWindowInsetsBottom() { |
| + return mWindowInsets.bottom; |
| + } |
| + |
| + @SuppressWarnings("deprecation") |
| + @Override |
| + protected boolean fitSystemWindows(Rect insets) { |
| + // For Lollipop and above, onApplyWindowInsets will set the insets. |
| + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { |
| + mWindowInsets.set(insets.left, insets.top, insets.right, insets.bottom); |
| + } |
| + return false; |
| + } |
| + |
| + @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
| + private static class InsetConsumerViewApi21 extends InsetConsumerView { |
| + /** |
| + * Creates an instance of {@link InsetConsumerView} for Android versions |
| + * L and above. |
| + * @param context The Context to create this {@link InsetConsumerView} |
| + * in. |
| + */ |
| + InsetConsumerViewApi21(Context context) { |
| + super(context); |
| + } |
| + |
| + @Override |
| + public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
| + mWindowInsets.set( |
| + insets.getSystemWindowInsetLeft(), |
| + insets.getSystemWindowInsetTop(), |
| + insets.getSystemWindowInsetRight(), |
| + insets.getSystemWindowInsetBottom()); |
| + return insets; |
| + } |
| + } |
| +} |