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 | |
| 19 | import android.content.res.CompatibilityInfo; |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 20 | import android.content.res.Configuration; |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 21 | |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 22 | import java.util.Objects; |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 23 | |
| 24 | /** @hide */ |
| 25 | public class DisplayAdjustments { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 26 | public static final DisplayAdjustments DEFAULT_DISPLAY_ADJUSTMENTS = new DisplayAdjustments(); |
| 27 | |
| 28 | private volatile CompatibilityInfo mCompatInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO; |
Andrii Kulian | a8a9bc5 | 2016-10-14 11:00:13 -0700 | [diff] [blame] | 29 | private Configuration mConfiguration; |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 30 | |
| 31 | public DisplayAdjustments() { |
| 32 | } |
| 33 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 34 | public DisplayAdjustments(Configuration configuration) { |
Andrii Kulian | a8a9bc5 | 2016-10-14 11:00:13 -0700 | [diff] [blame] | 35 | mConfiguration = new Configuration(configuration != null |
| 36 | ? configuration : Configuration.EMPTY); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Craig Mautner | 1abaa53 | 2013-06-28 12:03:32 -0700 | [diff] [blame] | 39 | public DisplayAdjustments(DisplayAdjustments daj) { |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 40 | setCompatibilityInfo(daj.mCompatInfo); |
Andrii Kulian | a8a9bc5 | 2016-10-14 11:00:13 -0700 | [diff] [blame] | 41 | mConfiguration = new Configuration(daj.mConfiguration != null |
| 42 | ? daj.mConfiguration : Configuration.EMPTY); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 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 | |
| 58 | public CompatibilityInfo getCompatibilityInfo() { |
| 59 | return mCompatInfo; |
| 60 | } |
| 61 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 62 | public void setConfiguration(Configuration configuration) { |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 63 | if (this == DEFAULT_DISPLAY_ADJUSTMENTS) { |
| 64 | throw new IllegalArgumentException( |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 65 | "setConfiguration: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS"); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 66 | } |
Andrii Kulian | a8a9bc5 | 2016-10-14 11:00:13 -0700 | [diff] [blame] | 67 | mConfiguration.setTo(configuration != null ? configuration : Configuration.EMPTY); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 70 | public Configuration getConfiguration() { |
| 71 | return mConfiguration; |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public int hashCode() { |
| 76 | int hash = 17; |
Adam Lesinski | 4ece3d6 | 2016-06-16 18:05:41 -0700 | [diff] [blame] | 77 | hash = hash * 31 + Objects.hashCode(mCompatInfo); |
| 78 | hash = hash * 31 + Objects.hashCode(mConfiguration); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 79 | return hash; |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public boolean equals(Object o) { |
| 84 | if (!(o instanceof DisplayAdjustments)) { |
| 85 | return false; |
| 86 | } |
| 87 | DisplayAdjustments daj = (DisplayAdjustments)o; |
Kenny Root | e6585b3 | 2013-12-13 12:00:26 -0800 | [diff] [blame] | 88 | return Objects.equals(daj.mCompatInfo, mCompatInfo) && |
Wale Ogunwale | 7c72668 | 2015-02-06 17:34:28 -0800 | [diff] [blame] | 89 | Objects.equals(daj.mConfiguration, mConfiguration); |
Craig Mautner | 48d0d18 | 2013-06-11 07:53:06 -0700 | [diff] [blame] | 90 | } |
| 91 | } |