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.view.View; | |
12 import android.view.WindowInsets; | |
13 | |
14 /** | |
15 * 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.
| |
16 * 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.
| |
17 * hierarchy. | |
18 */ | |
19 public class InsetConsumerView extends View { | |
20 | |
21 protected final Rect mWindowInsets; | |
22 | |
23 /** | |
24 * Constructs a new {@link InsetConsumerView} for the appropriate Android | |
25 * version. | |
26 * @param context The Context the view is running in, through which it can | |
27 * 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.
| |
28 * @return an instance of a InsetConsumerView. | |
29 */ | |
30 public static InsetConsumerView create(Context context) { | |
31 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { | |
32 return new InsetConsumerView(context); | |
33 } | |
34 return new InsetConsumerViewApi21(context); | |
35 } | |
36 | |
37 /** | |
38 * Creates an instance of {@link InsetConsumerView}. | |
39 * @param context The Context to create this {@link InsetConsumerView} in. | |
40 */ | |
41 public InsetConsumerView(Context context) { | |
42 super(context); | |
43 setVisibility(INVISIBLE); | |
44 mWindowInsets = new Rect(); | |
45 } | |
46 | |
47 /** | |
48 * Returns the left {@link WindowInsets} in pixels. | |
49 * @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.
| |
50 */ | |
51 public int getSystemWindowInsetsLeft() { | |
52 return mWindowInsets.left; | |
53 } | |
54 | |
55 /** | |
56 * Returns the top {@link WindowInsets} in pixels. | |
57 * @return The top system window inset. | |
58 */ | |
59 public int getSystemWindowInsetsTop() { | |
60 return mWindowInsets.top; | |
61 } | |
62 | |
63 /** | |
64 * Returns the right {@link WindowInsets} in pixels. | |
65 * @return The right system window inset. | |
66 */ | |
67 public int getSystemWindowInsetsRight() { | |
68 return mWindowInsets.right; | |
69 } | |
70 | |
71 /** | |
72 * Returns the bottom {@link WindowInsets} in pixels. | |
73 * @return The bottom system window inset. | |
74 */ | |
75 public int getSystemWindowInsetsBottom() { | |
76 return mWindowInsets.bottom; | |
77 } | |
78 | |
79 @SuppressWarnings("deprecation") | |
80 @Override | |
81 protected boolean fitSystemWindows(Rect insets) { | |
82 // For Lollipop and above, onApplyWindowInsets will set the insets. | |
83 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { | |
84 mWindowInsets.set(insets.left, insets.top, insets.right, insets.bott om); | |
85 } | |
86 return false; | |
87 } | |
88 | |
89 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | |
90 private static class InsetConsumerViewApi21 extends InsetConsumerView { | |
91 /** | |
92 * Creates an instance of {@link InsetConsumerView} for Android versions | |
93 * L and above. | |
94 * @param context The Context to create this {@link InsetConsumerView} | |
95 * in. | |
96 */ | |
97 InsetConsumerViewApi21(Context context) { | |
98 super(context); | |
99 } | |
100 | |
101 @Override | |
102 public WindowInsets onApplyWindowInsets(WindowInsets insets) { | |
103 mWindowInsets.set( | |
104 insets.getSystemWindowInsetLeft(), | |
105 insets.getSystemWindowInsetTop(), | |
106 insets.getSystemWindowInsetRight(), | |
107 insets.getSystemWindowInsetBottom()); | |
108 return insets; | |
109 } | |
110 } | |
111 } | |
OLD | NEW |