blob: e0f1b3a3f079b0b7a4c54cbfa6421b2321c6dfc0 [file] [log] [blame]
Craig Mautner88c05892013-06-28 09:47:45 -07001/*
2 * Copyright (C) 2013 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
17package android.content.res;
18
19import android.os.IBinder;
20
21/** @hide */
22public final class ResourcesKey {
23 final String mResDir;
24 final float mScale;
25 private final int mHash;
26 private final IBinder mToken;
27
28 public final int mDisplayId;
29 public final Configuration mOverrideConfiguration = new Configuration();
30
31 public ResourcesKey(String resDir, int displayId, Configuration overrideConfiguration,
32 float scale, IBinder token) {
33 mResDir = resDir;
34 mDisplayId = displayId;
35 if (overrideConfiguration != null) {
36 mOverrideConfiguration.setTo(overrideConfiguration);
37 }
38 mScale = scale;
39 mToken = token;
40
41 int hash = 17;
42 hash = 31 * hash + (mResDir == null ? 0 : mResDir.hashCode());
43 hash = 31 * hash + mDisplayId;
44 hash = 31 * hash + (mOverrideConfiguration != null
45 ? mOverrideConfiguration.hashCode() : 0);
46 hash = 31 * hash + Float.floatToIntBits(mScale);
47 mHash = hash;
48 }
49
50 public boolean hasOverrideConfiguration() {
51 return !Configuration.EMPTY.equals(mOverrideConfiguration);
52 }
53
54 @Override
55 public int hashCode() {
56 return mHash;
57 }
58
59 @Override
60 public boolean equals(Object obj) {
61 if (!(obj instanceof ResourcesKey)) {
62 return false;
63 }
64 ResourcesKey peer = (ResourcesKey) obj;
Adam Lesinski54130de2014-08-20 10:49:13 -070065 if (mResDir != peer.mResDir) {
66 if (mResDir == null || peer.mResDir == null) {
67 return false;
68 } else if (!mResDir.equals(peer.mResDir)) {
69 return false;
70 }
Craig Mautner88c05892013-06-28 09:47:45 -070071 }
72 if (mDisplayId != peer.mDisplayId) {
73 return false;
74 }
75 if (mOverrideConfiguration != peer.mOverrideConfiguration) {
76 if (mOverrideConfiguration == null || peer.mOverrideConfiguration == null) {
77 return false;
78 }
79 if (!mOverrideConfiguration.equals(peer.mOverrideConfiguration)) {
80 return false;
81 }
82 }
83 if (mScale != peer.mScale) {
84 return false;
85 }
86 return true;
87 }
88
89 @Override
90 public String toString() {
91 return Integer.toHexString(mHash);
92 }
93}