RequestKey.java revision 40662f4b39e795d9c64502b13036e7c37fa2d373
1/*
2 * Copyright (C) 2013 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
17package com.android.bitmap;
18
19import android.content.res.AssetFileDescriptor;
20
21
22import java.io.IOException;
23import java.io.InputStream;
24
25/**
26 * The decode task uses this class to get input to decode. You must implement at least one of
27 * {@link #createFd()} or {@link #createInputStream()}. {@link DecodeTask} will prioritize
28 * {@link #createFd()} before falling back to {@link #createInputStream()}.
29 * <p>
30 * Objects of this type will also serve as cache keys to fetch cached data for {@link PooledCache}s,
31 * so they must implement {@link #equals(Object)} and {@link #hashCode()}.
32 */
33
34public interface RequestKey {
35
36    @Override
37    public boolean equals(Object o);
38
39    @Override
40    public int hashCode();
41
42    /**
43     * Create an {@link AssetFileDescriptor} for a local file stored on the device. This method will
44     * be called first; if it returns null, {@link #createInputStream()} will be called.
45     */
46    public AssetFileDescriptor createFd() throws IOException;
47
48    /**
49     * Create an {@link InputStream} for a file. This method will be called if {@link #createFd()}
50     * returns null.
51     */
52    public InputStream createInputStream() throws IOException;
53
54    /**
55     * Return true if the image source may have be oriented in either portrait or landscape, and
56     * will need to be automatically re-oriented based on accompanying Exif metadata.
57     */
58    public boolean hasOrientationExif() throws IOException;
59}