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