1 /* 2 * Copyright (C) 2015 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.messaging.datamodel.media; 17 18 import com.android.messaging.datamodel.media.MediaResourceManager.MediaResourceLoadListener; 19 20 import java.util.List; 21 22 /** 23 * A mix-in style class that wraps around a normal, threading-agnostic MediaRequest object with 24 * functionalities offered by {@link BindableMediaRequest} to allow for async processing. 25 */ 26 class AsyncMediaRequestWrapper<T extends RefCountedMediaResource> extends BindableMediaRequest<T> { 27 28 /** 29 * Create a new async media request wrapper instance given the listener. 30 */ 31 public static <T extends RefCountedMediaResource> AsyncMediaRequestWrapper<T> 32 createWith(final MediaRequest<T> wrappedRequest, 33 final MediaResourceLoadListener<T> listener) { 34 return new AsyncMediaRequestWrapper<T>(listener, wrappedRequest); 35 } 36 37 private final MediaRequest<T> mWrappedRequest; 38 39 private AsyncMediaRequestWrapper(final MediaResourceLoadListener<T> listener, 40 final MediaRequest<T> wrappedRequest) { 41 super(listener); 42 mWrappedRequest = wrappedRequest; 43 } 44 45 @Override 46 public String getKey() { 47 return mWrappedRequest.getKey(); 48 } 49 50 @Override 51 public MediaCache<T> getMediaCache() { 52 return mWrappedRequest.getMediaCache(); 53 } 54 55 @Override 56 public int getRequestType() { 57 return mWrappedRequest.getRequestType(); 58 } 59 60 @Override 61 public T loadMediaBlocking(List<MediaRequest<T>> chainedTask) throws Exception { 62 return mWrappedRequest.loadMediaBlocking(chainedTask); 63 } 64 65 @Override 66 public int getCacheId() { 67 return mWrappedRequest.getCacheId(); 68 } 69 70 @Override 71 public MediaRequestDescriptor<T> getDescriptor() { 72 return mWrappedRequest.getDescriptor(); 73 } 74 }