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 android.text.TextUtils; 19 20 import java.util.List; 21 22 public class FakeImageRequest implements MediaRequest<FakeImageResource> { 23 public static final String INVALID_KEY = "invalid"; 24 private final String mKey; 25 private final int mSize; 26 FakeImageRequest(final String key, final int size)27 public FakeImageRequest(final String key, final int size) { 28 mKey = key; 29 mSize = size; 30 } 31 32 @Override getKey()33 public String getKey() { 34 return mKey; 35 } 36 37 @Override loadMediaBlocking(List<MediaRequest<FakeImageResource>> chainedTask)38 public FakeImageResource loadMediaBlocking(List<MediaRequest<FakeImageResource>> chainedTask) 39 throws Exception { 40 if (TextUtils.equals(mKey, INVALID_KEY)) { 41 throw new Exception(); 42 } else { 43 return new FakeImageResource(mSize, mKey); 44 } 45 } 46 47 @Override getCacheId()48 public int getCacheId() { 49 return FakeMediaCacheManager.FAKE_IMAGE_CACHE; 50 } 51 52 @SuppressWarnings("unchecked") 53 @Override getMediaCache()54 public MediaCache<FakeImageResource> getMediaCache() { 55 return (MediaCache<FakeImageResource>) MediaCacheManager.get().getOrCreateMediaCacheById( 56 getCacheId()); 57 } 58 59 @Override getRequestType()60 public int getRequestType() { 61 return MediaRequest.REQUEST_LOAD_MEDIA; 62 } 63 64 @Override getDescriptor()65 public MediaRequestDescriptor<FakeImageResource> getDescriptor() { 66 return null; 67 } 68 } 69