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.mtp.MtpDevice; 20 import android.mtp.MtpObjectInfo; 21 22 import com.android.gallery3d.ingest.MtpDeviceIndex; 23 24 import java.io.InputStream; 25 26 public class MtpThumbnailDrawable extends AutoThumbnailDrawable<MtpObjectInfo> { setImage(MtpObjectInfo data)27 public void setImage(MtpObjectInfo data) { 28 if (data == null) { 29 setImage(null, 0, 0); 30 } else { 31 setImage(data, data.getImagePixWidth(), data.getImagePixHeight()); 32 } 33 } 34 35 @Override getPreferredImageBytes(MtpObjectInfo data)36 protected byte[] getPreferredImageBytes(MtpObjectInfo data) { 37 if (data == null) { 38 return null; 39 } 40 MtpDevice device = MtpDeviceIndex.getInstance().getDevice(); 41 if (device != null) { 42 return device.getThumbnail(data.getObjectHandle()); 43 } else { 44 return null; 45 } 46 } 47 48 @Override getFallbackImageStream(MtpObjectInfo data)49 protected InputStream getFallbackImageStream(MtpObjectInfo data) { 50 // No fallback 51 return null; 52 } 53 54 @Override dataChangedLocked(MtpObjectInfo data)55 protected boolean dataChangedLocked(MtpObjectInfo data) { 56 // We only fetch the MtpObjectInfo once when creating 57 // the index so checking the reference is enough 58 return mData == data; 59 } 60 61 } 62