1 /* 2 * Copyright (C) 2008 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 com.android.ide.common.rendering.api; 18 19 import com.android.layoutlib.api.IDensityBasedResourceValue; 20 import com.android.resources.ResourceType; 21 22 @SuppressWarnings("deprecation") 23 public class DensityBasedResourceValue extends ResourceValue implements IDensityBasedResourceValue { 24 25 private com.android.resources.Density mDensity; 26 DensityBasedResourceValue(ResourceType type, String name, String value, com.android.resources.Density density, boolean isFramework)27 public DensityBasedResourceValue(ResourceType type, String name, String value, 28 com.android.resources.Density density, boolean isFramework) { 29 super(type, name, value, isFramework); 30 mDensity = density; 31 } 32 33 /** 34 * Returns the density for which this resource is configured. 35 * @return the density. 36 */ getResourceDensity()37 public com.android.resources.Density getResourceDensity() { 38 return mDensity; 39 } 40 41 /** Legacy method, do not call 42 * @deprecated use {@link #getResourceDensity()} instead. 43 */ 44 @Override 45 @Deprecated getDensity()46 public Density getDensity() { 47 return Density.getEnum(mDensity.getDpiValue()); 48 } 49 50 @Override toString()51 public String toString() { 52 return "DensityBasedResourceValue [" 53 + getResourceType() + "/" + getName() + " = " + getValue() 54 + " (density:" + mDensity +", framework:" + isFramework() + ")]"; 55 } 56 57 /* (non-Javadoc) 58 * @see java.lang.Object#hashCode() 59 */ 60 @Override hashCode()61 public int hashCode() { 62 final int prime = 31; 63 int result = super.hashCode(); 64 result = prime * result + ((mDensity == null) ? 0 : mDensity.hashCode()); 65 return result; 66 } 67 68 /* (non-Javadoc) 69 * @see java.lang.Object#equals(java.lang.Object) 70 */ 71 @Override equals(Object obj)72 public boolean equals(Object obj) { 73 if (this == obj) 74 return true; 75 if (!super.equals(obj)) 76 return false; 77 if (getClass() != obj.getClass()) 78 return false; 79 DensityBasedResourceValue other = (DensityBasedResourceValue) obj; 80 if (mDensity == null) { 81 if (other.mDensity != null) 82 return false; 83 } else if (!mDensity.equals(other.mDensity)) 84 return false; 85 return true; 86 } 87 } 88