1 /*
2  * Copyright (C) 2012 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 package com.android.dreams.phototable;
17 
18 import android.content.Context;
19 import android.content.SharedPreferences;
20 
21 import java.io.InputStream;
22 import java.util.Collection;
23 import java.util.LinkedList;
24 
25 /**
26  * Loads images from a variety of sources.
27  */
28 public class PhotoSourcePlexor extends PhotoSource {
29     private static final String TAG = "PhotoTable.PhotoSourcePlexor";
30 
31     private final PhotoSource mPicasaSource;
32     private final PhotoSource mLocalSource;
33 
PhotoSourcePlexor(Context context, SharedPreferences settings)34     public PhotoSourcePlexor(Context context, SharedPreferences settings) {
35         super(context, settings);
36         mSourceName = TAG;
37         mPicasaSource = new PicasaSource(context, settings);
38         mLocalSource = new LocalSource(context, settings);
39     }
40 
41     @Override
findAlbums()42     public Collection<AlbumData> findAlbums() {
43         log(TAG, "finding albums");
44         LinkedList<AlbumData> foundAlbums = new LinkedList<AlbumData>();
45 
46         foundAlbums.addAll(mPicasaSource.findAlbums());
47         log(TAG, "found " + foundAlbums.size() + " network albums");
48 
49         foundAlbums.addAll(mLocalSource.findAlbums());
50         log(TAG, "found " + foundAlbums.size() + " user albums");
51 
52         return foundAlbums;
53     }
54 
55     @Override
findImages(int howMany)56     protected Collection<ImageData> findImages(int howMany) {
57         log(TAG, "finding images");
58         LinkedList<ImageData> foundImages = new LinkedList<ImageData>();
59 
60         foundImages.addAll(mPicasaSource.findImages(howMany));
61         log(TAG, "found " + foundImages.size() + " network images");
62 
63         foundImages.addAll(mLocalSource.findImages(howMany));
64         log(TAG, "found " + foundImages.size() + " user images");
65 
66         return foundImages;
67     }
68 
69     @Override
getStream(ImageData data, int longSide)70     protected InputStream getStream(ImageData data, int longSide) {
71         return data.getStream(longSide);
72     }
73 
74     @Override
naturalNext(ImageData current)75     protected ImageData naturalNext(ImageData current) {
76         return current.naturalNext();
77     }
78 
79     @Override
naturalPrevious(ImageData current)80     protected ImageData naturalPrevious(ImageData current) {
81         return current.naturalPrevious();
82     }
83 
84     @Override
donePaging(ImageData current)85     protected void donePaging(ImageData current) {
86         current.donePaging();
87     }
88 }
89