• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.systemui;
18 
19 import android.app.Activity;
20 import android.content.Intent;
21 import android.service.dreams.Sandman;
22 
23 /**
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  */
30 public class Somnambulator extends Activity {
Somnambulator()31     public Somnambulator() {
32     }
33 
34     @Override
onStart()35     public void onStart() {
36         super.onStart();
37 
38         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,
46                     Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher_dreams));
47             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 {
51             boolean docked = launchIntent.hasCategory(Intent.CATEGORY_DESK_DOCK);
52             if (docked) {
53                 Sandman.startDreamWhenDockedIfAppropriate(this);
54             } else {
55                 Sandman.startDreamByUserRequest(this);
56             }
57         }
58         finish();
59     }
60 }
61