Home | History | Annotate | Download | only in wallpaper
      1 /*
      2  * Copyright (C) 2009 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 
     17 package com.cooliris.wallpaper;
     18 
     19 import java.io.IOException;
     20 import java.net.URISyntaxException;
     21 
     22 import com.cooliris.cache.CacheService;
     23 import com.cooliris.cache.ImageList;
     24 import com.cooliris.media.UriTexture;
     25 import com.cooliris.media.Util;
     26 
     27 import android.content.Context;
     28 import android.graphics.Bitmap;
     29 
     30 public class RandomDataSource implements Slideshow.DataSource {
     31 
     32     public Bitmap getBitmapForIndex(Context context, int currentSlideshowCounter) {
     33         ImageList list = CacheService.getImageList(context);
     34         // Once we have the id and the thumbid, we can return a bitmap
     35         // First we select a random numbers
     36         if (list.ids == null)
     37             return null;
     38         double random = Math.random();
     39         random *= list.ids.length;
     40         int index = (int) random;
     41         long cacheId = list.thumbids[index];
     42         final String uri = CacheService.BASE_CONTENT_STRING_IMAGES + list.ids[index];
     43         Bitmap retVal = null;
     44         try {
     45             retVal = UriTexture.createFromUri(context, uri, UriTexture.MAX_RESOLUTION, UriTexture.MAX_RESOLUTION, cacheId, null);
     46             if (retVal != null) {
     47                 retVal = Util.rotate(retVal, list.orientation[index]);
     48             }
     49         } catch (OutOfMemoryError e) {
     50             ;
     51         } catch (IOException e) {
     52             ;
     53         } catch (URISyntaxException e) {
     54             ;
     55         }
     56         return retVal;
     57     }
     58 
     59 }
     60