blob: 0dd6d9283223e1925052a96a3bb8b79fd50559a1 [file] [log] [blame]
Jeff Brown11159e92012-10-11 15:58:37 -07001/*
Daniel Sandler32f6fd52012-09-06 01:22:59 -04002 * 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
17package com.android.systemui;
18
19import android.app.Activity;
20import android.content.Intent;
Jeff Brown11159e92012-10-11 15:58:37 -070021import android.service.dreams.Sandman;
Daniel Sandler32f6fd52012-09-06 01:22:59 -040022
Jeff Brown11159e92012-10-11 15:58:37 -070023/**
24 * A simple activity that launches a dream.
25 * <p>
26 * Note: This Activity is special. If this class is moved to another package or
27 * renamed, be sure to update the component name in {@link Sandman}.
28 * </p>
29 */
Daniel Sandler32f6fd52012-09-06 01:22:59 -040030public class Somnambulator extends Activity {
Daniel Sandler32f6fd52012-09-06 01:22:59 -040031 public Somnambulator() {
32 }
Daniel Sandler3a120292012-09-28 11:28:09 -040033
Daniel Sandler32f6fd52012-09-06 01:22:59 -040034 @Override
35 public void onStart() {
36 super.onStart();
Jeff Brown11159e92012-10-11 15:58:37 -070037
Daniel Sandler32f6fd52012-09-06 01:22:59 -040038 final Intent launchIntent = getIntent();
39 final String action = launchIntent.getAction();
40 if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
41 Intent shortcutIntent = new Intent(this, Somnambulator.class);
42 shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
43 | Intent.FLAG_ACTIVITY_NEW_TASK);
44 Intent resultIntent = new Intent();
45 resultIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Daniel Sandlerb055aa82012-10-26 15:11:53 -040046 Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher_dreams));
Daniel Sandler32f6fd52012-09-06 01:22:59 -040047 resultIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
48 resultIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.start_dreams));
49 setResult(RESULT_OK, resultIntent);
50 } else {
Daniel Sandler3a120292012-09-28 11:28:09 -040051 boolean docked = launchIntent.hasCategory(Intent.CATEGORY_DESK_DOCK);
Jeff Brown11159e92012-10-11 15:58:37 -070052 if (docked) {
53 Sandman.startDreamWhenDockedIfAppropriate(this);
Daniel Sandler3a120292012-09-28 11:28:09 -040054 } else {
Jeff Brown11159e92012-10-11 15:58:37 -070055 Sandman.startDreamByUserRequest(this);
Daniel Sandler32f6fd52012-09-06 01:22:59 -040056 }
57 }
58 finish();
59 }
Daniel Sandler32f6fd52012-09-06 01:22:59 -040060}