• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.launcher3.shadows;
17 
18 import static org.robolectric.shadow.api.Shadow.directlyOn;
19 
20 import android.graphics.Point;
21 import android.graphics.Rect;
22 import android.view.Display;
23 
24 import org.robolectric.annotation.Implements;
25 import org.robolectric.annotation.RealObject;
26 import org.robolectric.shadows.ShadowDisplay;
27 
28 /**
29  * Extension of {@link ShadowDisplay} with missing shadow methods
30  */
31 @Implements(value = Display.class)
32 public class LShadowDisplay extends ShadowDisplay {
33 
34     private final Rect mInsets = new Rect();
35 
36     @RealObject Display realObject;
37 
38     /**
39      * Sets the insets for the display
40      */
setInsets(Rect insets)41     public void setInsets(Rect insets) {
42         mInsets.set(insets);
43     }
44 
45     @Override
getCurrentSizeRange(Point outSmallestSize, Point outLargestSize)46     protected void getCurrentSizeRange(Point outSmallestSize, Point outLargestSize) {
47         directlyOn(realObject, Display.class).getCurrentSizeRange(outSmallestSize, outLargestSize);
48         outSmallestSize.x -= mInsets.left + mInsets.right;
49         outLargestSize.x -= mInsets.left + mInsets.right;
50 
51         outSmallestSize.y -= mInsets.top + mInsets.bottom;
52         outLargestSize.y -= mInsets.top + mInsets.bottom;
53     }
54 }
55