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