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