Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(451)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/InsetObserverView.java

Issue 1386403003: Resize only the virtual viewport when the OSK triggers a resize. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/InsetConsumerView/InsetObserverView Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 system window insets (OSK, status ba r) for
16 * later use.
17 */
18 public class InsetObserverView extends View {
19
20 protected final Rect mWindowInsets;
21
22 /**
23 * Constructs a new {@link InsetObserverView} for the appropriate Android ve rsion.
24 * @param context The Context the view is running in, through which it can a ccess the current
25 * theme, resources, etc.
26 * @return an instance of a InsetObserverView.
27 */
28 public static InsetObserverView create(Context context) {
29 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
30 return new InsetObserverView(context);
31 }
32 return new InsetObserverViewApi21(context);
33 }
34
35 /**
36 * Creates an instance of {@link InsetObserverView}.
37 * @param context The Context to create this {@link InsetObserverView} in.
38 */
39 public InsetObserverView(Context context) {
40 super(context);
41 setVisibility(INVISIBLE);
42 mWindowInsets = new Rect();
43 }
44
45 /**
46 * Returns the left {@link WindowInsets} in pixels.
47 */
48 public int getSystemWindowInsetsLeft() {
49 return mWindowInsets.left;
50 }
51
52 /**
53 * Returns the top {@link WindowInsets} in pixels.
54 */
55 public int getSystemWindowInsetsTop() {
56 return mWindowInsets.top;
57 }
58
59 /**
60 * Returns the right {@link WindowInsets} in pixels.
61 */
62 public int getSystemWindowInsetsRight() {
63 return mWindowInsets.right;
64 }
65
66 /**
67 * Returns the bottom {@link WindowInsets} in pixels.
68 */
69 public int getSystemWindowInsetsBottom() {
70 return mWindowInsets.bottom;
71 }
72
73 @SuppressWarnings("deprecation")
74 @Override
75 protected boolean fitSystemWindows(Rect insets) {
76 // For Lollipop and above, onApplyWindowInsets will set the insets.
77 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
78 mWindowInsets.set(insets.left, insets.top, insets.right, insets.bott om);
79 }
80 return false;
81 }
82
83 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
84 private static class InsetObserverViewApi21 extends InsetObserverView {
85 /**
86 * Creates an instance of {@link InsetObserverView} for Android versions L and above.
87 * @param context The Context to create this {@link InsetObserverView} i n.
88 */
89 InsetObserverViewApi21(Context context) {
90 super(context);
91 }
92
93 @Override
94 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
95 mWindowInsets.set(
96 insets.getSystemWindowInsetLeft(),
97 insets.getSystemWindowInsetTop(),
98 insets.getSystemWindowInsetRight(),
99 insets.getSystemWindowInsetBottom());
100 return insets;
101 }
102 }
103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698