18ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde/* 28ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde * Copyright (C) 2013 The Android Open Source Project 38ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde * 48ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde * Licensed under the Apache License, Version 2.0 (the "License"); 58ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde * you may not use this file except in compliance with the License. 68ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde * You may obtain a copy of the License at 78ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde * 88ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde * http://www.apache.org/licenses/LICENSE-2.0 98ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde * 108ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde * Unless required by applicable law or agreed to in writing, software 118ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde * distributed under the License is distributed on an "AS IS" BASIS, 128ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 138ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde * See the License for the specific language governing permissions and 148ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde * limitations under the License. 158ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde */ 168ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 178ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohdepackage com.android.camera.data; 188ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 198ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohdeimport android.content.ContentResolver; 208ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohdeimport android.content.Context; 218ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohdeimport android.graphics.Bitmap; 228ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohdeimport android.graphics.Point; 23005bb2f26e73c4c9daad41b615f6dd414396f625Alan Newbergerimport android.graphics.drawable.BitmapDrawable; 248ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohdeimport android.net.Uri; 258ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohdeimport android.provider.MediaStore; 268ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohdeimport android.view.View; 278ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohdeimport android.widget.ImageView; 288ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 298ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohdeimport com.android.camera.Storage; 308ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohdeimport com.android.camera.data.FilmstripItemAttributes.Attributes; 318ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohdeimport com.android.camera.debug.Log; 328ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohdeimport com.android.camera.util.CameraUtil; 338ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohdeimport com.android.camera.util.Size; 348ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohdeimport com.android.camera2.R; 3577d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohdeimport com.bumptech.glide.DrawableRequestBuilder; 3677d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohdeimport com.bumptech.glide.GenericRequestBuilder; 378ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohdeimport com.bumptech.glide.Glide; 3877d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohdeimport com.bumptech.glide.load.resource.drawable.GlideDrawable; 398ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohdeimport com.google.common.base.Optional; 408ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 418ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohdeimport java.io.FileInputStream; 428ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohdeimport java.io.FileNotFoundException; 438ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 4477d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohdeimport javax.annotation.Nonnull; 4577d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde 468ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde/** 478ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde * Backing data for a single photo displayed in the filmstrip. 488ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde */ 498ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohdepublic class PhotoItem extends FilmstripItemBase<FilmstripItemData> { 508ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde private static final Log.Tag TAG = new Log.Tag("PhotoItem"); 518ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde private static final int MAX_PEEK_BITMAP_PIXELS = 1600000; // 1.6 * 4 MBs. 528ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 538ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde private static final FilmstripItemAttributes PHOTO_ITEM_ATTRIBUTES = 548ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde new FilmstripItemAttributes.Builder() 558ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde .with(Attributes.CAN_SHARE) 568ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde .with(Attributes.CAN_EDIT) 578ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde .with(Attributes.CAN_DELETE) 588ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde .with(Attributes.CAN_SWIPE_AWAY) 598ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde .with(Attributes.CAN_ZOOM_IN_PLACE) 608ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde .with(Attributes.HAS_DETAILED_CAPTURE_INFO) 618ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde .with(Attributes.IS_IMAGE) 628ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde .build(); 638ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 648ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde private final PhotoItemFactory mPhotoItemFactory; 658ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 66995083b53be47e1e27133e403da0b63a03d07ea7Alan Newberger private Optional<Bitmap> mSessionPlaceholderBitmap = Optional.absent(); 678ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 6877d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde public PhotoItem(Context context, GlideFilmstripManager manager, FilmstripItemData data, 6977d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde PhotoItemFactory photoItemFactory) { 7077d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde super(context, manager, data, PHOTO_ITEM_ATTRIBUTES); 718ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde mPhotoItemFactory = photoItemFactory; 728ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } 738ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 74005bb2f26e73c4c9daad41b615f6dd414396f625Alan Newberger /** 75005bb2f26e73c4c9daad41b615f6dd414396f625Alan Newberger * A bitmap that if present, is a high resolution bitmap from a temporary 76005bb2f26e73c4c9daad41b615f6dd414396f625Alan Newberger * session, that should be used as a placeholder in place of placeholder/ 77005bb2f26e73c4c9daad41b615f6dd414396f625Alan Newberger * thumbnail loading. 78005bb2f26e73c4c9daad41b615f6dd414396f625Alan Newberger * 79005bb2f26e73c4c9daad41b615f6dd414396f625Alan Newberger * @param sessionPlaceholderBitmap a Bitmap to set as a placeholder 80005bb2f26e73c4c9daad41b615f6dd414396f625Alan Newberger */ 81995083b53be47e1e27133e403da0b63a03d07ea7Alan Newberger public void setSessionPlaceholderBitmap(Optional<Bitmap> sessionPlaceholderBitmap) { 82005bb2f26e73c4c9daad41b615f6dd414396f625Alan Newberger mSessionPlaceholderBitmap = sessionPlaceholderBitmap; 83005bb2f26e73c4c9daad41b615f6dd414396f625Alan Newberger } 84005bb2f26e73c4c9daad41b615f6dd414396f625Alan Newberger 858ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde @Override 868ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde public String toString() { 878ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde return "PhotoItem: " + mData.toString(); 888ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } 898ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 908ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde @Override 918ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde public boolean delete() { 928ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde ContentResolver cr = mContext.getContentResolver(); 938ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde cr.delete(PhotoDataQuery.CONTENT_URI, 948ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde MediaStore.Images.ImageColumns._ID + "=" + mData.getContentId(), null); 958ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde return super.delete(); 968ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } 978ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 988ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde @Override 998ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde public Optional<MediaDetails> getMediaDetails() { 1008ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde Optional<MediaDetails> optionalDetails = super.getMediaDetails(); 1018ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde if (optionalDetails.isPresent()) { 1028ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde MediaDetails mediaDetails = optionalDetails.get(); 1038ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde MediaDetails.extractExifInfo(mediaDetails, mData.getFilePath()); 1048ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde mediaDetails.addDetail(MediaDetails.INDEX_ORIENTATION, mData.getOrientation()); 1058ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } 1068ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde return optionalDetails; 1078ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } 1088ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 1098ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde @Override 1108ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde public FilmstripItem refresh() { 1118ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde // TODO: Consider simply replacing the data inline 1128ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde return mPhotoItemFactory.get(mData.getUri()); 1138ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } 1148ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 1158ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde @Override 11677d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde public View getView(Optional<View> optionalView, LocalFilmstripDataAdapter adapter, 11777d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde boolean isInProgress, VideoClickedCallback videoClickedCallback) { 1188ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde ImageView imageView; 1198ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 1208ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde if (optionalView.isPresent()) { 1218ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde imageView = (ImageView) optionalView.get(); 1228ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } else { 123d70b22919f8d212bf11abd6e6724b3a395ef02c1Alan Newberger imageView = new ImageView(mContext); 1248ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde imageView.setTag(R.id.mediadata_tag_viewtype, getItemViewType().ordinal()); 1258ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } 1268ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 127005bb2f26e73c4c9daad41b615f6dd414396f625Alan Newberger fillImageView(imageView); 1288ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 1298ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde return imageView; 1308ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } 1318ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 132005bb2f26e73c4c9daad41b615f6dd414396f625Alan Newberger protected void fillImageView(final ImageView imageView) { 13377d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde renderTinySize(mData.getUri()).into(imageView); 1348ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 1358ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde // TODO consider having metadata have a "get description" string 1368ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde // or some other way of selecting rendering details based on metadata. 1378ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde int stringId = R.string.photo_date_content_description; 1388ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde if (getMetadata().isPanorama() || 1398ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde getMetadata().isPanorama360()) { 1408ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde stringId = R.string.panorama_date_content_description; 1418ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } else if (getMetadata().isUsePanoramaViewer()) { 1428ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde // assume it's a PhotoSphere 1438ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde stringId = R.string.photosphere_date_content_description; 1448ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } else if (this.getMetadata().isHasRgbzData()) { 1458ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde stringId = R.string.refocus_date_content_description; 1468ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } 1478ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 1488ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde imageView.setContentDescription(mContext.getResources().getString( 1498ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde stringId, 1508ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde mDateFormatter.format(mData.getLastModifiedDate()))); 1518ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } 1528ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 1538ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde @Override 15477d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde public void recycle(@Nonnull View view) { 1558ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde Glide.clear(view); 156995083b53be47e1e27133e403da0b63a03d07ea7Alan Newberger mSessionPlaceholderBitmap = Optional.absent(); 1578ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } 1588ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 1598ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde @Override 1608ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde public FilmstripItemType getItemViewType() { 1618ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde return FilmstripItemType.PHOTO; 1628ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } 1638ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 1648ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde @Override 16577d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde public void renderTiny(@Nonnull View view) { 16677d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde if (view instanceof ImageView) { 16777d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde renderTinySize(mData.getUri()).into((ImageView) view); 16877d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde } else { 16977d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde Log.w(TAG, "renderTiny was called with an object that is not an ImageView!"); 17077d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde } 17177d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde } 1728ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 17377d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde @Override 17477d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde public void renderThumbnail(@Nonnull View view) { 17577d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde if (view instanceof ImageView) { 17677d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde renderScreenSize(mData.getUri()).into((ImageView) view); 17777d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde } else { 17877d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde Log.w(TAG, "renderThumbnail was called with an object that is not an ImageView!"); 17977d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde } 18077d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde } 181005bb2f26e73c4c9daad41b615f6dd414396f625Alan Newberger 18277d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde @Override 18377d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde public void renderFullRes(@Nonnull View view) { 18477d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde if (view instanceof ImageView) { 18577d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde renderFullSize(mData.getUri()).into((ImageView) view); 186005bb2f26e73c4c9daad41b615f6dd414396f625Alan Newberger } else { 18777d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde Log.w(TAG, "renderFullRes was called with an object that is not an ImageView!"); 188005bb2f26e73c4c9daad41b615f6dd414396f625Alan Newberger } 18977d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde } 19077d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde 19177d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde private GenericRequestBuilder<Uri, ?, ?, GlideDrawable> renderTinySize(Uri uri) { 19277d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde return mGlideManager.loadTinyThumb(uri, generateSignature(mData)); 19377d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde } 19477d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde 19577d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde private DrawableRequestBuilder<Uri> renderScreenSize(Uri uri) { 19677d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde DrawableRequestBuilder<Uri> request = 197689348be49bf1e5e5f705d55915f87292d9506edPaul Rohde mGlideManager.loadScreen(uri, generateSignature(mData), mSuggestedSize); 198005bb2f26e73c4c9daad41b615f6dd414396f625Alan Newberger 19977d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde // If we have a non-null placeholder, use that and do NOT ever render a 20077d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde // tiny thumbnail to prevent un-intended "flash of low resolution image" 201995083b53be47e1e27133e403da0b63a03d07ea7Alan Newberger if (mSessionPlaceholderBitmap.isPresent()) { 2020ec045201975bc12ac12007615c099c5e98d202aAlan Newberger Log.v(TAG, "using session bitmap as placeholder"); 20377d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde return request.placeholder(new BitmapDrawable(mContext.getResources(), 204995083b53be47e1e27133e403da0b63a03d07ea7Alan Newberger mSessionPlaceholderBitmap.get())); 20577d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde } 20677d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde 20777d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde // If we do not have a placeholder bitmap, render a thumbnail with 20877d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde // the default placeholder resource like normal. 20977d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde return request 21077d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde .thumbnail(renderTinySize(uri)); 21177d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde } 21277d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde 21377d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde private DrawableRequestBuilder<Uri> renderFullSize(Uri uri) { 21477d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde Size size = mData.getDimensions(); 215689348be49bf1e5e5f705d55915f87292d9506edPaul Rohde return mGlideManager.loadFull(uri, generateSignature(mData), size) 21677d9f023e76816e5da7bd067ad46cc0e9c98623fPaul Rohde .thumbnail(renderScreenSize(uri)); 2178ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } 2188ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 2198ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde @Override 2208ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde public Optional<Bitmap> generateThumbnail(int boundingWidthPx, int boundingHeightPx) { 2218ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde FilmstripItemData data = getData(); 2228ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde final Bitmap bitmap; 2238ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 2248ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde if (getAttributes().isRendering()) { 225995083b53be47e1e27133e403da0b63a03d07ea7Alan Newberger return Storage.getPlaceholderForSession(data.getUri()); 2268ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } else { 2278ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 2288ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde FileInputStream stream; 2298ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 2308ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde try { 2318ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde stream = new FileInputStream(data.getFilePath()); 2328ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } catch (FileNotFoundException e) { 2338ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde Log.e(TAG, "File not found:" + data.getFilePath()); 2348ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde return Optional.absent(); 2358ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } 2368ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde int width = data.getDimensions().getWidth(); 2378ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde int height = data.getDimensions().getHeight(); 2388ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde int orientation = data.getOrientation(); 2398ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 2408ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde Point dim = CameraUtil.resizeToFill( 2418ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde width, 2428ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde height, 2438ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde orientation, 2448ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde boundingWidthPx, 2458ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde boundingHeightPx); 2468ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 2478ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde // If the orientation is not vertical 2488ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde if (orientation % 180 != 0) { 2498ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde int dummy = dim.x; 2508ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde dim.x = dim.y; 2518ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde dim.y = dummy; 2528ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } 2538ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 2548ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde bitmap = FilmstripItemUtils 2558ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde .loadImageThumbnailFromStream( 2568ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde stream, 2578ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde data.getDimensions().getWidth(), 2588ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde data.getDimensions().getHeight(), 2598ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde (int) (dim.x * 0.7f), (int) (dim.y * 0.7), 2608ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde data.getOrientation(), MAX_PEEK_BITMAP_PIXELS); 2618ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde 262995083b53be47e1e27133e403da0b63a03d07ea7Alan Newberger return Optional.fromNullable(bitmap); 263995083b53be47e1e27133e403da0b63a03d07ea7Alan Newberger } 2648ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde } 2658ee16b8a323ffa20e6fb1270d498ec445f64defcPaul Rohde} 266