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 import android.content.res.Resources; 21 import android.service.dreams.DreamService; 22 import android.view.LayoutInflater; 23 import android.view.ViewGroup; 24 25 import java.util.Set; 26 27 /** 28 * Example interactive screen saver: flick photos onto a table. 29 */ 30 public class PhotoTableDream extends DreamService { 31 public static final String TAG = "PhotoTableDream"; 32 private PhotoTable mTable; 33 34 @Override 35 public void onDreamingStarted() { 36 super.onDreamingStarted(); 37 setInteractive(true); 38 } 39 40 @Override 41 public void onAttachedToWindow() { 42 super.onAttachedToWindow(); 43 LayoutInflater inflater = 44 (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 45 AlbumSettings settings = AlbumSettings.getAlbumSettings( 46 getSharedPreferences(PhotoTableDreamSettings.PREFS_NAME, 0)); 47 if (settings.isConfigured()) { 48 ViewGroup view = (ViewGroup) inflater.inflate(R.layout.table, null); 49 PhotoTable table = (PhotoTable) view.findViewById(R.id.table); 50 table.setDream(this); 51 setContentView(view); 52 } else { 53 Resources resources = getResources(); 54 ViewGroup view = (ViewGroup) inflater.inflate(R.layout.bummer, null); 55 BummerView bummer = (BummerView) view.findViewById(R.id.bummer); 56 bummer.setAnimationParams(true, 57 resources.getInteger(R.integer.table_drop_period), 58 resources.getInteger(R.integer.fast_drop)); 59 setContentView(view); 60 } 61 setFullscreen(true); 62 } 63 } 64