SessionItem.java revision 8ee16b8a323ffa20e6fb1270d498ec445f64defc
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          int placeHolderResourceId, 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        imageView.setImageBitmap(placeholder);
81        imageView.setContentDescription(mContext.getResources().getString(
82                R.string.media_processing_content_description));
83        return imageView;
84    }
85
86    @Override
87    public FilmstripItemType getItemViewType() {
88        return FilmstripItemType.SESSION;
89    }
90
91    @Override
92    public void loadFullImage(int width, int height, View view) {
93    }
94
95    @Override
96    public boolean delete() {
97        return false;
98    }
99
100    @Override
101    public Optional<MediaDetails> getMediaDetails() {
102        return Optional.absent();
103    }
104
105    @Override
106    public FilmstripItem refresh() {
107        Size dimension = getSessionSize(mData.getUri());
108
109        mData = FilmstripItemData.Builder.from(mData)
110              .withDimensions(dimension)
111              .build();
112
113        return this;
114    }
115
116    @Override
117    public Metadata getMetadata() {
118        return mMetaData;
119    }
120
121    @Override
122    public FilmstripItemData getData() {
123        return mData;
124    }
125
126    @Override
127    public FilmstripItemAttributes getAttributes() {
128        return mAttributes;
129    }
130
131    @Override
132    public Optional<Bitmap> generateThumbnail(int boundingWidthPx, int boundingHeightPx) {
133        return Optional.absent();
134    }
135
136    @Override
137    public void recycle(View view) {
138        Glide.clear(view);
139    }
140
141}
142