Debian Codegraph @

layoutlib-api/src/main/java/com/android/ide/common/rendering/api/DensityBasedResourceValue.java

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