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