1 /*
2  * Copyright (C) 2017 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 package com.android.wallpaper.asset;
17 
18 import android.content.res.Resources;
19 
20 import com.bumptech.glide.load.Key;
21 
22 /**
23  * Image asset representing a Nexus stub APK resource.
24  */
25 public final class NexusStaticAsset extends ResourceAsset {
26     private final String mResName;
27 
28     /**
29      * @param res   Resources containing the asset.
30      * @param resId Resource ID referencing the asset.
31      */
NexusStaticAsset(Resources res, int resId, String resName)32     public NexusStaticAsset(Resources res, int resId, String resName) {
33         super(res, resId);
34         mResName = resName;
35     }
36 
37     @Override
getKey()38     public Key getKey() {
39         if (mKey == null) {
40             mKey = new PackageResourceKey(mRes, mResId, mResName);
41         }
42         return mKey;
43     }
44 
45     /**
46      * Glide caching key for resources from Nexus stub APK.
47      */
48     private static class PackageResourceKey extends ResourceAsset.PackageResourceKey {
49         private String mResName;
50 
PackageResourceKey(Resources res, int resId, String resName)51         public PackageResourceKey(Resources res, int resId, String resName) {
52             super(res, resId);
53             mResName = resName;
54         }
55 
56         @Override
getCacheKey()57         protected String getCacheKey() {
58             return "PackageResourceKey{"
59                     + "packageName=" + mPackageName
60                     + ",resId=" + mResId
61                     + ",resName=" + mResName
62                     + '}';
63         }
64     }
65 }
66