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.content.res.CompatibilityInfo;
20 import android.content.res.Configuration;
21 
22 import java.util.Objects;
23 
24 /** @hide */
25 public class DisplayAdjustments {
26     public static final boolean DEVELOPMENT_RESOURCES_DEPEND_ON_ACTIVITY_TOKEN = false;
27 
28     public static final DisplayAdjustments DEFAULT_DISPLAY_ADJUSTMENTS = new DisplayAdjustments();
29 
30     private volatile CompatibilityInfo mCompatInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
31     private Configuration mConfiguration = Configuration.EMPTY;
32 
DisplayAdjustments()33     public DisplayAdjustments() {
34     }
35 
DisplayAdjustments(Configuration configuration)36     public DisplayAdjustments(Configuration configuration) {
37         mConfiguration = configuration;
38     }
39 
DisplayAdjustments(DisplayAdjustments daj)40     public DisplayAdjustments(DisplayAdjustments daj) {
41         setCompatibilityInfo(daj.mCompatInfo);
42         mConfiguration = daj.mConfiguration;
43     }
44 
setCompatibilityInfo(CompatibilityInfo compatInfo)45     public void setCompatibilityInfo(CompatibilityInfo compatInfo) {
46         if (this == DEFAULT_DISPLAY_ADJUSTMENTS) {
47             throw new IllegalArgumentException(
48                     "setCompatbilityInfo: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS");
49         }
50         if (compatInfo != null && (compatInfo.isScalingRequired()
51                 || !compatInfo.supportsScreen())) {
52             mCompatInfo = compatInfo;
53         } else {
54             mCompatInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
55         }
56     }
57 
getCompatibilityInfo()58     public CompatibilityInfo getCompatibilityInfo() {
59         return mCompatInfo;
60     }
61 
setConfiguration(Configuration configuration)62     public void setConfiguration(Configuration configuration) {
63         if (this == DEFAULT_DISPLAY_ADJUSTMENTS) {
64             throw new IllegalArgumentException(
65                     "setConfiguration: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS");
66         }
67         mConfiguration = configuration;
68     }
69 
getConfiguration()70     public Configuration getConfiguration() {
71         return mConfiguration;
72     }
73 
74     @Override
hashCode()75     public int hashCode() {
76         int hash = 17;
77         hash = hash * 31 + mCompatInfo.hashCode();
78         if (DEVELOPMENT_RESOURCES_DEPEND_ON_ACTIVITY_TOKEN) {
79             hash = hash * 31 + (mConfiguration == null ? 0 : mConfiguration.hashCode());
80         }
81         return hash;
82     }
83 
84     @Override
equals(Object o)85     public boolean equals(Object o) {
86         if (!(o instanceof DisplayAdjustments)) {
87             return false;
88         }
89         DisplayAdjustments daj = (DisplayAdjustments)o;
90         return Objects.equals(daj.mCompatInfo, mCompatInfo) &&
91                 Objects.equals(daj.mConfiguration, mConfiguration);
92     }
93 }
94