Home | History | Annotate | Download | only in drawables
      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 
     17 package com.android.photos.drawables;
     18 
     19 import android.media.ExifInterface;
     20 import android.text.TextUtils;
     21 
     22 import java.io.FileInputStream;
     23 import java.io.FileNotFoundException;
     24 import java.io.IOException;
     25 import java.io.InputStream;
     26 
     27 public class DataUriThumbnailDrawable extends AutoThumbnailDrawable<String> {
     28 
     29     @Override
     30     protected byte[] getPreferredImageBytes(String data) {
     31         byte[] thumbnail = null;
     32         try {
     33             ExifInterface exif = new ExifInterface(data);
     34             if (exif.hasThumbnail()) {
     35                 thumbnail = exif.getThumbnail();
     36              }
     37         } catch (IOException e) { }
     38         return thumbnail;
     39     }
     40 
     41     @Override
     42     protected InputStream getFallbackImageStream(String data) {
     43         try {
     44             return new FileInputStream(data);
     45         } catch (FileNotFoundException e) {
     46             return null;
     47         }
     48     }
     49 
     50     @Override
     51     protected boolean dataChangedLocked(String data) {
     52         return !TextUtils.equals(mData, data);
     53     }
     54 }
     55