BitmapRequestKeyImpl.java revision ea356fbb2c76f0c8ed79901e800d0f7d62dc952d
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.example.bitmapsample;
18
19import android.content.res.AssetFileDescriptor;
20import android.os.ParcelFileDescriptor;
21
22import com.android.bitmap.RequestKey;
23
24import java.io.IOException;
25import java.io.InputStream;
26import java.net.MalformedURLException;
27import java.net.URL;
28
29public class BitmapRequestKeyImpl implements RequestKey {
30    public final String mUriString;
31    public final URL mUrl;
32
33    public BitmapRequestKeyImpl(String uriString) {
34        mUriString = uriString;
35        URL url = null;
36        try {
37            url = new URL(uriString);
38        } catch (MalformedURLException e) {
39            e.printStackTrace();
40        }
41        mUrl = url;
42    }
43
44    @Override
45    public boolean equals(Object o) {
46        if (o == null || !(o instanceof BitmapRequestKeyImpl)) {
47            return false;
48        }
49        final BitmapRequestKeyImpl other = (BitmapRequestKeyImpl) o;
50        return mUriString.equals(other.mUriString);
51    }
52
53    @Override
54    public int hashCode() {
55        int hash = 17;
56        hash += 31 * hash + mUriString.hashCode();
57        return hash;
58    }
59
60    @Override
61    public String toString() {
62        final StringBuilder sb = new StringBuilder("[");
63        sb.append(mUriString);
64        sb.append("]");
65        return sb.toString();
66    }
67
68    @Override
69    public ParcelFileDescriptor createFd() throws IOException {
70        return null;
71    }
72
73    @Override
74    public InputStream createInputStream() throws IOException {
75        return mUrl.openStream();
76    }
77
78    @Override
79    public boolean hasOrientationExif() throws IOException {
80        return false;
81    }
82
83}