• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 androidx.annotation.Nullable;
19 
20 import com.android.wallpaper.asset.ResourceAssetLoader.ResourceAssetFetcher;
21 
22 import com.bumptech.glide.load.Options;
23 import com.bumptech.glide.load.model.ModelLoader;
24 import com.bumptech.glide.load.model.ModelLoaderFactory;
25 import com.bumptech.glide.load.model.MultiModelLoaderFactory;
26 
27 import java.io.InputStream;
28 
29 /**
30  * Glide ModelLoader which loads InputStreams from PartnerStaticAssets.
31  */
32 public class SystemStaticAssetLoader implements ModelLoader<SystemStaticAsset, InputStream> {
33 
34     @Override
handles(SystemStaticAsset systemStaticAsset)35     public boolean handles(SystemStaticAsset systemStaticAsset) {
36         return true;
37     }
38 
39     @Nullable
40     @Override
buildLoadData(SystemStaticAsset systemStaticAsset, int unusedWidth, int unusedHeight, Options options)41     public LoadData<InputStream> buildLoadData(SystemStaticAsset systemStaticAsset, int unusedWidth,
42                                                int unusedHeight, Options options) {
43         return new LoadData<>(systemStaticAsset.getKey(),
44                 new ResourceAssetFetcher(systemStaticAsset));
45     }
46 
47     /**
48      * Factory that constructs {@link SystemStaticAssetLoader} instances.
49      */
50     public static class SystemStaticAssetLoaderFactory
51             implements ModelLoaderFactory<SystemStaticAsset, InputStream> {
SystemStaticAssetLoaderFactory()52         public SystemStaticAssetLoaderFactory() {
53         }
54 
55         @Override
build( MultiModelLoaderFactory multiFactory)56         public ModelLoader<SystemStaticAsset, InputStream> build(
57                 MultiModelLoaderFactory multiFactory) {
58             return new SystemStaticAssetLoader();
59         }
60 
61         @Override
teardown()62         public void teardown() {
63             // no-op
64         }
65     }
66 }
67