BitmapRequestKeyImpl.java revision 9c6ac19d4a3d39b7c2992060957920118ff56a65
1014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck/* 2014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * Copyright (C) 2013 The Android Open Source Project 3014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * 4014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * Licensed under the Apache License, Version 2.0 (the "License"); 5014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * you may not use this file except in compliance with the License. 6014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * You may obtain a copy of the License at 7014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * 8014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * http://www.apache.org/licenses/LICENSE-2.0 9014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * 10014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * Unless required by applicable law or agreed to in writing, software 11014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * distributed under the License is distributed on an "AS IS" BASIS, 12014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * See the License for the specific language governing permissions and 14014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck * limitations under the License. 15014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck */ 16014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck 17014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reckpackage com.example.bitmapsample; 18014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck 19014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reckimport com.android.bitmap.RequestKey; 20014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck 21014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reckimport java.io.IOException; 22014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reckimport java.io.InputStream; 23014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reckimport java.net.MalformedURLException; 24014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reckimport java.net.URL; 25014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck 265c3188e75e33c8edaf18af71fa681cd7759aee87Alan Viverettepublic class BitmapRequestKeyImpl implements RequestKey { 275c3188e75e33c8edaf18af71fa681cd7759aee87Alan Viverette public final String mUriString; 28014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck public final URL mUrl; 29014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck 30014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck public BitmapRequestKeyImpl(String uriString) { 31014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck mUriString = uriString; 325c3188e75e33c8edaf18af71fa681cd7759aee87Alan Viverette URL url = null; 33014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck try { 34617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette url = new URL(uriString); 35617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette } catch (MalformedURLException e) { 36617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette e.printStackTrace(); 37014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck } 38014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck mUrl = url; 39014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck } 40014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck 41014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck @Override 425c3188e75e33c8edaf18af71fa681cd7759aee87Alan Viverette public boolean equals(Object o) { 43014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck if (o == null || !(o instanceof BitmapRequestKeyImpl)) { 44014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck return false; 45014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck } 46617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette final BitmapRequestKeyImpl other = (BitmapRequestKeyImpl) o; 47617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette return mUriString.equals(other.mUriString); 48617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette } 49617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette 50617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette @Override 515c3188e75e33c8edaf18af71fa681cd7759aee87Alan Viverette public int hashCode() { 52599d2a49e84bf0a4ee752e263a2c29d2ae942c3eAlan Viverette int hash = 17; 53599d2a49e84bf0a4ee752e263a2c29d2ae942c3eAlan Viverette hash += 31 * hash + mUriString.hashCode(); 54599d2a49e84bf0a4ee752e263a2c29d2ae942c3eAlan Viverette return hash; 55599d2a49e84bf0a4ee752e263a2c29d2ae942c3eAlan Viverette } 56617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette 57617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette @Override 58014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck public String toString() { 59014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck final StringBuilder sb = new StringBuilder("["); 605c3188e75e33c8edaf18af71fa681cd7759aee87Alan Viverette sb.append(mUriString); 615c3188e75e33c8edaf18af71fa681cd7759aee87Alan Viverette sb.append("]"); 62014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck return sb.toString(); 63014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck } 64014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck 65014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck @Override 66014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck public Cancelable createFileDescriptorFactoryAsync(final RequestKey key, 67014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck final Callback callback) { 685c3188e75e33c8edaf18af71fa681cd7759aee87Alan Viverette return null; 69014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck } 70014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck 71014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck @Override 72014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck public InputStream createInputStream() throws IOException { 73014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck return mUrl.openStream(); 74014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck } 75014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck 76014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck @Override 775c3188e75e33c8edaf18af71fa681cd7759aee87Alan Viverette public boolean hasOrientationExif() throws IOException { 78014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck return false; 79014fea2a663ab0bc2d80a6293b84b2647a4a1895John Reck } 80 81}