• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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 
17 package android.view;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.compat.annotation.UnsupportedAppUsage;
22 import android.content.res.CompatibilityInfo;
23 import android.content.res.Configuration;
24 import android.ravenwood.annotation.RavenwoodKeepWholeClass;
25 
26 import java.util.Objects;
27 
28 /** @hide */
29 @RavenwoodKeepWholeClass
30 public class DisplayAdjustments {
31     public static final DisplayAdjustments DEFAULT_DISPLAY_ADJUSTMENTS = new DisplayAdjustments();
32 
33     private volatile CompatibilityInfo mCompatInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
34     private final Configuration mConfiguration = new Configuration(Configuration.EMPTY);
35 
36     @UnsupportedAppUsage
DisplayAdjustments()37     public DisplayAdjustments() {
38     }
39 
DisplayAdjustments(@ullable Configuration configuration)40     public DisplayAdjustments(@Nullable Configuration configuration) {
41         if (configuration != null) {
42             mConfiguration.setTo(configuration);
43         }
44     }
45 
DisplayAdjustments(@onNull DisplayAdjustments daj)46     public DisplayAdjustments(@NonNull DisplayAdjustments daj) {
47         setCompatibilityInfo(daj.mCompatInfo);
48         mConfiguration.setTo(daj.getConfiguration());
49     }
50 
51     @UnsupportedAppUsage
setCompatibilityInfo(@ullable CompatibilityInfo compatInfo)52     public void setCompatibilityInfo(@Nullable CompatibilityInfo compatInfo) {
53         if (this == DEFAULT_DISPLAY_ADJUSTMENTS) {
54             throw new IllegalArgumentException(
55                     "setCompatbilityInfo: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS");
56         }
57         if (compatInfo != null && (compatInfo.isScalingRequired()
58                 || !compatInfo.supportsScreen())) {
59             mCompatInfo = compatInfo;
60         } else {
61             mCompatInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
62         }
63     }
64 
getCompatibilityInfo()65     public CompatibilityInfo getCompatibilityInfo() {
66         return mCompatInfo;
67     }
68 
69     /**
70      * Updates the configuration for the DisplayAdjustments with new configuration.
71      * Default to EMPTY configuration if new configuration is {@code null}
72      * @param configuration new configuration
73      * @throws IllegalArgumentException if trying to modify DEFAULT_DISPLAY_ADJUSTMENTS
74      */
setConfiguration(@ullable Configuration configuration)75     public void setConfiguration(@Nullable Configuration configuration) {
76         if (this == DEFAULT_DISPLAY_ADJUSTMENTS) {
77             throw new IllegalArgumentException(
78                     "setConfiguration: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS");
79         }
80         mConfiguration.setTo(configuration != null ? configuration : Configuration.EMPTY);
81     }
82 
83     @UnsupportedAppUsage
84     @NonNull
getConfiguration()85     public Configuration getConfiguration() {
86         return mConfiguration;
87     }
88 
89     @Override
hashCode()90     public int hashCode() {
91         int hash = 17;
92         hash = hash * 31 + Objects.hashCode(mCompatInfo);
93         hash = hash * 31 + Objects.hashCode(mConfiguration);
94         return hash;
95     }
96 
97     @Override
equals(@ullable Object o)98     public boolean equals(@Nullable Object o) {
99         if (!(o instanceof DisplayAdjustments)) {
100             return false;
101         }
102         DisplayAdjustments daj = (DisplayAdjustments)o;
103         return Objects.equals(daj.mCompatInfo, mCompatInfo)
104                 && Objects.equals(daj.mConfiguration, mConfiguration);
105     }
106 }
107