SessionItem.java revision 51cafa0a35546a42c573357aa7a031a79cf9ba1b
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
34/**
35 * This is used to represent a local data item that is in progress and not
36 * yet in the media store.
37 */
38public class SessionItem implements FilmstripItem {
39    protected final Metadata mMetaData;
40    private FilmstripItemData mData;
41    private final FilmstripItemAttributes mAttributes;
42    private final Context mContext;
43
44    public SessionItem(Context context, Uri uri) {
45        mContext = context;
46        mMetaData = new Metadata();
47        mMetaData.setLoaded(true);
48
49        Date creationDate = new Date();
50        Size dimension = getSessionSize(uri);
51
52        mData = new FilmstripItemData.Builder(uri)
53              .withCreationDate(creationDate)
54              .withLastModifiedDate(creationDate)
55              .withDimensions(dimension)
56              .build();
57
58        mAttributes = FilmstripItemAttributes.DEFAULT;
59    }
60
61    private Size getSessionSize(Uri uri) {
62        Point size = Storage.getSizeForSession(uri);
63        return new Size(size.x, size.y);
64    }
65
66    @Override
67    public View getView(Optional<View> optionalView, int viewWidthPx, int viewHeightPx,
68          LocalFilmstripDataAdapter adapter, boolean isInProgress,
69          VideoClickedCallback videoClickedCallback) {
70        ImageView imageView;
71
72        if (optionalView.isPresent()) {
73            imageView = (ImageView) optionalView.get();
74        } else {
75            imageView = new ImageView(mContext);
76            imageView.setTag(R.id.mediadata_tag_viewtype, getItemViewType().ordinal());
77        }
78
79        Bitmap placeholder = Storage.getPlacerHolderForSession(mData.getUri());
80        if (placeholder != null) {
81            imageView.setImageBitmap(placeholder);
82        } else {
83            imageView.setImageResource(DEFAULT_PLACEHOLDER_RESOURCE);
84        }
85        imageView.setContentDescription(mContext.getResources().getString(
86                R.string.media_processing_content_description));
87        return imageView;
88    }
89
90    @Override
91    public FilmstripItemType getItemViewType() {
92        return FilmstripItemType.SESSION;
93    }
94
95    @Override
96    public void loadFullImage(int width, int height, View view) {
97    }
98
99    @Override
100    public boolean delete() {
101        return false;
102    }
103
104    @Override
105    public Optional<MediaDetails> getMediaDetails() {
106        return Optional.absent();
107    }
108
109    @Override
110    public FilmstripItem refresh() {
111        Size dimension = getSessionSize(mData.getUri());
112
113        mData = FilmstripItemData.Builder.from(mData)
114              .withDimensions(dimension)
115              .build();
116
117        return this;
118    }
119
120    @Override
121    public Metadata getMetadata() {
122        return mMetaData;
123    }
124
125    @Override
126    public FilmstripItemData getData() {
127        return mData;
128    }
129
130    @Override
131    public FilmstripItemAttributes getAttributes() {
132        return mAttributes;
133    }
134
135    @Override
136    public Optional<Bitmap> generateThumbnail(int boundingWidthPx, int boundingHeightPx) {
137        return Optional.absent();
138    }
139
140    @Override
141    public void recycle(View view) {
142        Glide.clear(view);
143    }
144
145    @Override
146    public Size getDimensions() {
147        return mData.getDimensions();
148    }
149
150    @Override
151    public int getOrientation() {
152        return mData.getOrientation();
153    }
154}
155