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.util.Assert; 19 20 /** 21 * An implementation of {@link MediaCacheManager} that creates caches specific to Bugle's needs. 22 * 23 * To create a new type of cache, add to the list of cache ids and create a new MediaCache<> 24 * for your cache id / media resource type in createMediaCacheById(). 25 */ 26 public class BugleMediaCacheManager extends MediaCacheManager { 27 // List of available cache ids. 28 public static final int DEFAULT_IMAGE_CACHE = 1; 29 public static final int AVATAR_IMAGE_CACHE = 2; 30 public static final int VCARD_CACHE = 3; 31 32 // VCard cache size - we compute the size by count, not by bytes. 33 private static final int VCARD_CACHE_SIZE = 5; 34 private static final int SHARED_IMAGE_CACHE_SIZE = 1024 * 10; // 10MB 35 36 @Override 37 protected MediaCache<?> createMediaCacheById(final int id) { 38 switch (id) { 39 case DEFAULT_IMAGE_CACHE: 40 return new PoolableImageCache(SHARED_IMAGE_CACHE_SIZE, id, "DefaultImageCache"); 41 42 case AVATAR_IMAGE_CACHE: 43 return new PoolableImageCache(id, "AvatarImageCache"); 44 45 case VCARD_CACHE: 46 return new MediaCache<VCardResource>(VCARD_CACHE_SIZE, id, "VCardCache"); 47 48 default: 49 Assert.fail("BugleMediaCacheManager: unsupported cache id " + id); 50 break; 51 } 52 return null; 53 } 54 } 55