blob: 834dd7b6e7d83dabeefbb02d4ff27a77cc48dd04 [file] [log] [blame]
Craig Mautner48d0d182013-06-11 07:53:06 -07001/*
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
17package android.view;
18
Artur Satayevad9254c2019-12-10 17:47:54 +000019import android.compat.annotation.UnsupportedAppUsage;
Craig Mautner48d0d182013-06-11 07:53:06 -070020import android.content.res.CompatibilityInfo;
Wale Ogunwale7c726682015-02-06 17:34:28 -080021import android.content.res.Configuration;
Craig Mautner48d0d182013-06-11 07:53:06 -070022
Kenny Roote6585b32013-12-13 12:00:26 -080023import java.util.Objects;
Craig Mautner48d0d182013-06-11 07:53:06 -070024
25/** @hide */
26public class DisplayAdjustments {
Craig Mautner48d0d182013-06-11 07:53:06 -070027 public static final DisplayAdjustments DEFAULT_DISPLAY_ADJUSTMENTS = new DisplayAdjustments();
28
29 private volatile CompatibilityInfo mCompatInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
Andrii Kuliana8a9bc52016-10-14 11:00:13 -070030 private Configuration mConfiguration;
Craig Mautner48d0d182013-06-11 07:53:06 -070031
Mathew Inwooda570dee2018-08-17 14:56:00 +010032 @UnsupportedAppUsage
Craig Mautner48d0d182013-06-11 07:53:06 -070033 public DisplayAdjustments() {
34 }
35
Wale Ogunwale7c726682015-02-06 17:34:28 -080036 public DisplayAdjustments(Configuration configuration) {
Andrii Kuliana8a9bc52016-10-14 11:00:13 -070037 mConfiguration = new Configuration(configuration != null
38 ? configuration : Configuration.EMPTY);
Craig Mautner48d0d182013-06-11 07:53:06 -070039 }
40
Craig Mautner1abaa532013-06-28 12:03:32 -070041 public DisplayAdjustments(DisplayAdjustments daj) {
Wale Ogunwale7c726682015-02-06 17:34:28 -080042 setCompatibilityInfo(daj.mCompatInfo);
Andrii Kuliana8a9bc52016-10-14 11:00:13 -070043 mConfiguration = new Configuration(daj.mConfiguration != null
44 ? daj.mConfiguration : Configuration.EMPTY);
Craig Mautner48d0d182013-06-11 07:53:06 -070045 }
46
Mathew Inwooda570dee2018-08-17 14:56:00 +010047 @UnsupportedAppUsage
Craig Mautner48d0d182013-06-11 07:53:06 -070048 public void setCompatibilityInfo(CompatibilityInfo compatInfo) {
49 if (this == DEFAULT_DISPLAY_ADJUSTMENTS) {
50 throw new IllegalArgumentException(
51 "setCompatbilityInfo: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS");
52 }
53 if (compatInfo != null && (compatInfo.isScalingRequired()
54 || !compatInfo.supportsScreen())) {
55 mCompatInfo = compatInfo;
56 } else {
57 mCompatInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
58 }
59 }
60
61 public CompatibilityInfo getCompatibilityInfo() {
62 return mCompatInfo;
63 }
64
Wale Ogunwale7c726682015-02-06 17:34:28 -080065 public void setConfiguration(Configuration configuration) {
Craig Mautner48d0d182013-06-11 07:53:06 -070066 if (this == DEFAULT_DISPLAY_ADJUSTMENTS) {
67 throw new IllegalArgumentException(
Wale Ogunwale7c726682015-02-06 17:34:28 -080068 "setConfiguration: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS");
Craig Mautner48d0d182013-06-11 07:53:06 -070069 }
Andrii Kuliana8a9bc52016-10-14 11:00:13 -070070 mConfiguration.setTo(configuration != null ? configuration : Configuration.EMPTY);
Craig Mautner48d0d182013-06-11 07:53:06 -070071 }
72
Mathew Inwooda570dee2018-08-17 14:56:00 +010073 @UnsupportedAppUsage
Wale Ogunwale7c726682015-02-06 17:34:28 -080074 public Configuration getConfiguration() {
75 return mConfiguration;
Craig Mautner48d0d182013-06-11 07:53:06 -070076 }
77
78 @Override
79 public int hashCode() {
80 int hash = 17;
Adam Lesinski4ece3d62016-06-16 18:05:41 -070081 hash = hash * 31 + Objects.hashCode(mCompatInfo);
82 hash = hash * 31 + Objects.hashCode(mConfiguration);
Craig Mautner48d0d182013-06-11 07:53:06 -070083 return hash;
84 }
85
86 @Override
87 public boolean equals(Object o) {
88 if (!(o instanceof DisplayAdjustments)) {
89 return false;
90 }
91 DisplayAdjustments daj = (DisplayAdjustments)o;
Kenny Roote6585b32013-12-13 12:00:26 -080092 return Objects.equals(daj.mCompatInfo, mCompatInfo) &&
Wale Ogunwale7c726682015-02-06 17:34:28 -080093 Objects.equals(daj.mConfiguration, mConfiguration);
Craig Mautner48d0d182013-06-11 07:53:06 -070094 }
95}