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.os.IBinder; 21 22 import com.android.internal.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 volatile IBinder mActivityToken; 32 33 public DisplayAdjustments() { 34 } 35 36 public DisplayAdjustments(IBinder token) { 37 mActivityToken = token; 38 } 39 40 public DisplayAdjustments(DisplayAdjustments daj) { 41 this (daj.getCompatibilityInfo(), daj.getActivityToken()); 42 } 43 44 public DisplayAdjustments(CompatibilityInfo compatInfo, IBinder token) { 45 setCompatibilityInfo(compatInfo); 46 mActivityToken = token; 47 } 48 49 public void setCompatibilityInfo(CompatibilityInfo compatInfo) { 50 if (this == DEFAULT_DISPLAY_ADJUSTMENTS) { 51 throw new IllegalArgumentException( 52 "setCompatbilityInfo: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS"); 53 } 54 if (compatInfo != null && (compatInfo.isScalingRequired() 55 || !compatInfo.supportsScreen())) { 56 mCompatInfo = compatInfo; 57 } else { 58 mCompatInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO; 59 } 60 } 61 62 public CompatibilityInfo getCompatibilityInfo() { 63 return mCompatInfo; 64 } 65 66 public void setActivityToken(IBinder token) { 67 if (this == DEFAULT_DISPLAY_ADJUSTMENTS) { 68 throw new IllegalArgumentException( 69 "setActivityToken: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS"); 70 } 71 mActivityToken = token; 72 } 73 74 public IBinder getActivityToken() { 75 return mActivityToken; 76 } 77 78 @Override 79 public int hashCode() { 80 int hash = 17; 81 hash = hash * 31 + mCompatInfo.hashCode(); 82 if (DEVELOPMENT_RESOURCES_DEPEND_ON_ACTIVITY_TOKEN) { 83 hash = hash * 31 + (mActivityToken == null ? 0 : mActivityToken.hashCode()); 84 } 85 return hash; 86 } 87 88 @Override 89 public boolean equals(Object o) { 90 if (!(o instanceof DisplayAdjustments)) { 91 return false; 92 } 93 DisplayAdjustments daj = (DisplayAdjustments)o; 94 return Objects.equal(daj.mCompatInfo, mCompatInfo) && 95 Objects.equal(daj.mActivityToken, mActivityToken); 96 } 97 } 98