1d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd/*
2d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Copyright (C) 2015 The Android Open Source Project
3d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd *
4d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Licensed under the Apache License, Version 2.0 (the "License");
5d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * you may not use this file except in compliance with the License.
6d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * You may obtain a copy of the License at
7d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd *
8d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd *      http://www.apache.org/licenses/LICENSE-2.0
9d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd *
10d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Unless required by applicable law or agreed to in writing, software
11d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * distributed under the License is distributed on an "AS IS" BASIS,
12d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * See the License for the specific language governing permissions and
14d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * limitations under the License.
15d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */
16d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpackage com.android.messaging.datamodel.media;
17d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
18d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.Context;
19d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.graphics.RectF;
20d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
21d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.google.common.base.Joiner;
22d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
23d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport java.util.List;
24d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
25d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpublic abstract class CompositeImageRequestDescriptor extends ImageRequestDescriptor {
26d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    protected final List<? extends ImageRequestDescriptor> mDescriptors;
27d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    private final String mKey;
28d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
29d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public CompositeImageRequestDescriptor(final List<? extends ImageRequestDescriptor> descriptors,
30d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd            final int desiredWidth, final int desiredHeight) {
31d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        super(desiredWidth, desiredHeight);
32d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        mDescriptors = descriptors;
33d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
34d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        final String[] keyParts = new String[descriptors.size()];
35d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        for (int i = 0; i < descriptors.size(); i++) {
36d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd            keyParts[i] = descriptors.get(i).getKey();
37d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        }
38d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        mKey = Joiner.on(",").skipNulls().join(keyParts);
39d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    }
40d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
41d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    /**
42d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd     * Gets a key that uniquely identify all the underlying image resource to be loaded (e.g. Uri or
43d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd     * file path).
44d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd     */
45d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    @Override
46d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public String getKey() {
47d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        return mKey;
48d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    }
49d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
50d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public List<? extends ImageRequestDescriptor> getChildRequestDescriptors(){
51d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        return mDescriptors;
52d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    }
53d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
54d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public abstract List<RectF> getChildRequestTargetRects();
55d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public abstract CompositeImageRequest<?> buildBatchImageRequest(final Context context);
56d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd
57d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    @Override
58d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    public MediaRequest<ImageResource> buildSyncMediaRequest(final Context context) {
59d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd        return buildBatchImageRequest(context);
60d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd    }
61d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd}
62