Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 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 | |
Artur Satayev | ad9254c | 2019-12-10 17:47:54 +0000 | [diff] [blame] | 19 | import android.compat.annotation.UnsupportedAppUsage; |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 20 | import android.content.res.CompatibilityInfo; |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 21 | import android.content.res.Configuration; |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 22 | |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 23 | import java.util.Objects; |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 24 | |
| 25 | /** @hide */ |
| 26 | public class DisplayAdjustments { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 27 | public static final DisplayAdjustments DEFAULT_DISPLAY_ADJUSTMENTS = new DisplayAdjustments(); |
| 28 | |
| 29 | private volatile CompatibilityInfo mCompatInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO; |
Andrii Kulian | a8a9bc5 | 2016-10-14 11:00:13 -0700 | [diff] [blame] | 30 | private Configuration mConfiguration; |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 31 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 32 | @UnsupportedAppUsage |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 33 | public DisplayAdjustments() { |
| 34 | } |
| 35 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 36 | public DisplayAdjustments(Configuration configuration) { |
Andrii Kulian | a8a9bc5 | 2016-10-14 11:00:13 -0700 | [diff] [blame] | 37 | mConfiguration = new Configuration(configuration != null |
| 38 | ? configuration : Configuration.EMPTY); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Craig Mautner | 1abaa53 | 2013-06-28 12:03:32 -0700 | [diff] [blame] | 41 | public DisplayAdjustments(DisplayAdjustments daj) { |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 42 | setCompatibilityInfo(daj.mCompatInfo); |
Andrii Kulian | a8a9bc5 | 2016-10-14 11:00:13 -0700 | [diff] [blame] | 43 | mConfiguration = new Configuration(daj.mConfiguration != null |
| 44 | ? daj.mConfiguration : Configuration.EMPTY); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 47 | @UnsupportedAppUsage |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 48 | 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 Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 65 | public void setConfiguration(Configuration configuration) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 66 | if (this == DEFAULT_DISPLAY_ADJUSTMENTS) { |
| 67 | throw new IllegalArgumentException( |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 68 | "setConfiguration: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS"); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 69 | } |
Andrii Kulian | a8a9bc5 | 2016-10-14 11:00:13 -0700 | [diff] [blame] | 70 | mConfiguration.setTo(configuration != null ? configuration : Configuration.EMPTY); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Mathew Inwood | a570dee | 2018-08-17 14:56:00 +0100 | [diff] [blame] | 73 | @UnsupportedAppUsage |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 74 | public Configuration getConfiguration() { |
| 75 | return mConfiguration; |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public int hashCode() { |
| 80 | int hash = 17; |
Adam Lesinski | 4ece3d6 | 2016-06-16 18:05:41 -0700 | [diff] [blame] | 81 | hash = hash * 31 + Objects.hashCode(mCompatInfo); |
| 82 | hash = hash * 31 + Objects.hashCode(mConfiguration); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 83 | 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 Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 92 | return Objects.equals(daj.mCompatInfo, mCompatInfo) && |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 93 | Objects.equals(daj.mConfiguration, mConfiguration); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 94 | } |
| 95 | } |