SessionItem.java revision 995083b53be47e1e27133e403da0b63a03d07ea7
1/* 2 * Copyright (C) 2014 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.android.camera.data; 18 19import android.content.Context; 20import android.graphics.Bitmap; 21import android.graphics.Point; 22import android.net.Uri; 23import android.view.View; 24import android.widget.ImageView; 25 26import com.android.camera.Storage; 27import com.android.camera.util.Size; 28import com.android.camera2.R; 29import com.bumptech.glide.Glide; 30import com.google.common.base.Optional; 31 32import java.util.Date; 33 34import javax.annotation.Nonnull; 35 36/** 37 * This is used to represent a local data item that is in progress and not 38 * yet in the media store. 39 */ 40public class SessionItem implements FilmstripItem { 41 protected final Metadata mMetaData; 42 private FilmstripItemData mData; 43 private final FilmstripItemAttributes mAttributes; 44 private final Context mContext; 45 private final Uri mUri; 46 47 public SessionItem(Context context, Uri uri) { 48 mContext = context; 49 mUri = uri; 50 51 mMetaData = new Metadata(); 52 mMetaData.setLoaded(true); 53 54 Date creationDate = new Date(); 55 Size dimension = getSessionSize(uri); 56 57 mData = new FilmstripItemData.Builder(uri) 58 .withCreationDate(creationDate) 59 .withLastModifiedDate(creationDate) 60 .withDimensions(dimension) 61 .build(); 62 63 mAttributes = new FilmstripItemAttributes.Builder() 64 .with(FilmstripItemAttributes.Attributes.IS_RENDERING) 65 .build(); 66 67 } 68 69 private Size getSessionSize(Uri uri) { 70 Point size = Storage.getSizeForSession(uri); 71 return new Size(size.x, size.y); 72 } 73 74 @Override 75 public View getView(Optional<View> optionalView, LocalFilmstripDataAdapter adapter, 76 boolean isInProgress, VideoClickedCallback videoClickedCallback) { 77 ImageView imageView; 78 79 if (optionalView.isPresent()) { 80 imageView = (ImageView) optionalView.get(); 81 } else { 82 imageView = new ImageView(mContext); 83 imageView.setTag(R.id.mediadata_tag_viewtype, getItemViewType().ordinal()); 84 } 85 86 Optional<Bitmap> placeholder = Storage.getPlaceholderForSession(mData.getUri()); 87 if (placeholder.isPresent()) { 88 imageView.setImageBitmap(placeholder.get()); 89 } else { 90 imageView.setImageResource(GlideFilmstripManager.DEFAULT_PLACEHOLDER_RESOURCE); 91 } 92 imageView.setContentDescription(mContext.getResources().getString( 93 R.string.media_processing_content_description)); 94 return imageView; 95 } 96 97 @Override 98 public FilmstripItemType getItemViewType() { 99 return FilmstripItemType.SESSION; 100 } 101 102 @Override 103 public void setSuggestedSize(int widthPx, int heightPx) { } 104 105 @Override 106 public void renderTiny(@Nonnull View view) { } 107 108 @Override 109 public void renderThumbnail(@Nonnull View view) { } 110 111 @Override 112 public void renderFullRes(@Nonnull View view) { } 113 114 @Override 115 public boolean delete() { 116 return false; 117 } 118 119 @Override 120 public Optional<MediaDetails> getMediaDetails() { 121 return Optional.absent(); 122 } 123 124 @Override 125 public FilmstripItem refresh() { 126 Size dimension = getSessionSize(mData.getUri()); 127 128 mData = FilmstripItemData.Builder.from(mData) 129 .withDimensions(dimension) 130 .build(); 131 132 return this; 133 } 134 135 @Override 136 public Metadata getMetadata() { 137 return mMetaData; 138 } 139 140 @Override 141 public FilmstripItemData getData() { 142 return mData; 143 } 144 145 @Override 146 public FilmstripItemAttributes getAttributes() { 147 return mAttributes; 148 } 149 150 @Override 151 public Optional<Bitmap> generateThumbnail(int boundingWidthPx, int boundingHeightPx) { 152 return Storage.getPlaceholderForSession(mUri); 153 } 154 155 @Override 156 public void recycle(@Nonnull View view) { 157 Glide.clear(view); 158 } 159 160 @Override 161 public Size getDimensions() { 162 return mData.getDimensions(); 163 } 164 165 @Override 166 public int getOrientation() { 167 return mData.getOrientation(); 168 } 169} 170