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.Point;
21import android.net.Uri;
22import android.os.Bundle;
23import android.view.View;
24import android.widget.ImageView;
25
26import com.android.camera.Storage;
27import com.android.camera2.R;
28import com.bumptech.glide.Glide;
29import com.bumptech.glide.load.DecodeFormat;
30
31import java.util.Date;
32import java.util.concurrent.TimeUnit;
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 LocalSessionData implements LocalData {
39
40    private Uri mUri;
41    // Units are GMT epoch milliseconds.
42    private long mDateTaken;
43    protected final Bundle mMetaData;
44    private int mWidth;
45    private int mHeight;
46
47    public LocalSessionData(Uri uri) {
48        mUri = uri;
49        mMetaData = new Bundle();
50        mDateTaken = new Date().getTime();
51        refreshSize(uri);
52    }
53
54    private void refreshSize(Uri uri) {
55        Point size = Storage.getSizeForSession(uri);
56        mWidth = size.x;
57        mHeight = size.y;
58    }
59
60    @Override
61    public View getView(Context context, View recycled, int thumbWidth, int thumbHeight,
62            int placeholderResourcedId, LocalDataAdapter adapter, boolean isInProgress) {
63        final ImageView imageView;
64        if (recycled != null) {
65            imageView = (ImageView) recycled;
66        } else {
67            imageView = new ImageView(context);
68            imageView.setTag(R.id.mediadata_tag_viewtype, getItemViewType().ordinal());
69        }
70
71        byte[] jpegData = Storage.getJpegForSession(mUri);
72        int currentVersion = Storage.getJpegVersionForSession(mUri);
73        Glide.with(context)
74            .loadFromImage(jpegData, mUri.toString() + currentVersion)
75            .skipDiskCache(true)
76            .fitCenter()
77            .into(imageView);
78
79        imageView.setContentDescription(context.getResources().getString(
80                R.string.media_processing_content_description));
81        return imageView;
82    }
83
84    @Override
85    public LocalDataViewType getItemViewType() {
86        return LocalDataViewType.SESSION;
87    }
88
89    @Override
90    public void loadFullImage(Context context, int width, int height, View view,
91            LocalDataAdapter adapter) {
92
93    }
94
95    @Override
96    public long getDateTaken() {
97        return mDateTaken;
98    }
99
100    @Override
101    public long getDateModified() {
102        // Convert to seconds because LocalData interface specifies that this
103        // method should return seconds and mDateTaken is in milliseconds.
104        return TimeUnit.MILLISECONDS.toSeconds(mDateTaken);
105    }
106
107    @Override
108    public String getTitle() {
109        return mUri.toString();
110    }
111
112    @Override
113    public boolean isDataActionSupported(int actions) {
114        return false;
115    }
116
117    @Override
118    public boolean delete(Context c) {
119        return false;
120    }
121
122    @Override
123    public void onFullScreen(boolean fullScreen) {
124
125    }
126
127    @Override
128    public boolean canSwipeInFullScreen() {
129        return true;
130    }
131
132    @Override
133    public String getPath() {
134        return "";
135    }
136
137    @Override
138    public String getMimeType() {
139        return null;
140    }
141
142    @Override
143    public MediaDetails getMediaDetails(Context context) {
144        return null;
145    }
146
147    @Override
148    public int getLocalDataType() {
149        return LOCAL_IN_PROGRESS_DATA;
150    }
151
152    @Override
153    public long getSizeInBytes() {
154        return 0;
155    }
156
157    @Override
158    public LocalData refresh(Context context) {
159        refreshSize(mUri);
160        return this;
161    }
162
163    @Override
164    public long getContentId() {
165        return 0;
166    }
167
168    @Override
169    public Bundle getMetadata() {
170        return mMetaData;
171    }
172
173    @Override
174    public String getSignature() {
175        return "";
176    }
177
178    @Override
179    public boolean isMetadataUpdated() {
180        return true;
181    }
182
183    @Override
184    public int getRotation() {
185        return 0;
186    }
187
188    @Override
189    public int getWidth() {
190        return mWidth;
191    }
192
193    @Override
194    public int getHeight() {
195        return mHeight;
196    }
197
198    @Override
199    public int getViewType() {
200        return VIEW_TYPE_REMOVABLE;
201    }
202
203    @Override
204    public double[] getLatLong() {
205        return null;
206    }
207
208    @Override
209    public boolean isUIActionSupported(int action) {
210        return false;
211    }
212
213    @Override
214    public void prepare() {
215
216    }
217
218    @Override
219    public void recycle(View view) {
220        Glide.clear(view);
221    }
222
223    @Override
224    public Uri getUri() {
225        return mUri;
226    }
227}
228