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