blob: 4ae3825a2c3a23e75411a3f02462aadce989b250 [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;
Wink Saville05e6dde2014-08-31 19:24:10 -070065
66 if ((mResDir == null) && (peer.mResDir != null)) {
67 return false;
68 }
69 if ((mResDir != null) && (peer.mResDir == null)) {
70 return false;
71 }
72 if ((mResDir != null) && (peer.mResDir != null)) {
73 if (!mResDir.equals(peer.mResDir)) {
Adam Lesinski54130de2014-08-20 10:49:13 -070074 return false;
75 }
Craig Mautner88c05892013-06-28 09:47:45 -070076 }
77 if (mDisplayId != peer.mDisplayId) {
78 return false;
79 }
80 if (mOverrideConfiguration != peer.mOverrideConfiguration) {
81 if (mOverrideConfiguration == null || peer.mOverrideConfiguration == null) {
82 return false;
83 }
84 if (!mOverrideConfiguration.equals(peer.mOverrideConfiguration)) {
85 return false;
86 }
87 }
88 if (mScale != peer.mScale) {
89 return false;
90 }
91 return true;
92 }
93
94 @Override
95 public String toString() {
96 return Integer.toHexString(mHash);
97 }
98}