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.content.Context; 19 import android.graphics.RectF; 20 21 import com.google.common.base.Joiner; 22 23 import java.util.List; 24 25 public abstract class CompositeImageRequestDescriptor extends ImageRequestDescriptor { 26 protected final List<? extends ImageRequestDescriptor> mDescriptors; 27 private final String mKey; 28 29 public CompositeImageRequestDescriptor(final List<? extends ImageRequestDescriptor> descriptors, 30 final int desiredWidth, final int desiredHeight) { 31 super(desiredWidth, desiredHeight); 32 mDescriptors = descriptors; 33 34 final String[] keyParts = new String[descriptors.size()]; 35 for (int i = 0; i < descriptors.size(); i++) { 36 keyParts[i] = descriptors.get(i).getKey(); 37 } 38 mKey = Joiner.on(",").skipNulls().join(keyParts); 39 } 40 41 /** 42 * Gets a key that uniquely identify all the underlying image resource to be loaded (e.g. Uri or 43 * file path). 44 */ 45 @Override 46 public String getKey() { 47 return mKey; 48 } 49 50 public List<? extends ImageRequestDescriptor> getChildRequestDescriptors(){ 51 return mDescriptors; 52 } 53 54 public abstract List<RectF> getChildRequestTargetRects(); 55 public abstract CompositeImageRequest<?> buildBatchImageRequest(final Context context); 56 57 @Override 58 public MediaRequest<ImageResource> buildSyncMediaRequest(final Context context) { 59 return buildBatchImageRequest(context); 60 } 61 } 62