1 /* 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 17 package android.content.res; 18 19 import android.annotation.NonNull; 20 21 import java.util.Objects; 22 23 /** @hide */ 24 public final class ResourcesKey { 25 private final String mResDir; 26 private final float mScale; 27 private final int mHash; 28 29 public final int mDisplayId; 30 @NonNull 31 public final Configuration mOverrideConfiguration; 32 ResourcesKey(String resDir, int displayId, Configuration overrideConfiguration, float scale)33 public ResourcesKey(String resDir, int displayId, Configuration overrideConfiguration, 34 float scale) { 35 mResDir = resDir; 36 mDisplayId = displayId; 37 mOverrideConfiguration = overrideConfiguration != null 38 ? overrideConfiguration : Configuration.EMPTY; 39 mScale = scale; 40 41 int hash = 17; 42 hash = 31 * hash + (mResDir == null ? 0 : mResDir.hashCode()); 43 hash = 31 * hash + mDisplayId; 44 hash = 31 * hash + mOverrideConfiguration.hashCode(); 45 hash = 31 * hash + Float.floatToIntBits(mScale); 46 mHash = hash; 47 } 48 hasOverrideConfiguration()49 public boolean hasOverrideConfiguration() { 50 return !Configuration.EMPTY.equals(mOverrideConfiguration); 51 } 52 53 @Override hashCode()54 public int hashCode() { 55 return mHash; 56 } 57 58 @Override equals(Object obj)59 public boolean equals(Object obj) { 60 if (!(obj instanceof ResourcesKey)) { 61 return false; 62 } 63 ResourcesKey peer = (ResourcesKey) obj; 64 65 if (!Objects.equals(mResDir, peer.mResDir)) { 66 return false; 67 } 68 if (mDisplayId != peer.mDisplayId) { 69 return false; 70 } 71 if (!mOverrideConfiguration.equals(peer.mOverrideConfiguration)) { 72 return false; 73 } 74 if (mScale != peer.mScale) { 75 return false; 76 } 77 return true; 78 } 79 80 @Override toString()81 public String toString() { 82 return Integer.toHexString(mHash); 83 } 84 } 85