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