Jeff Brown | 11159e9 | 2012-10-11 15:58:37 -0700 | [diff] [blame] | 1 | /* |
Daniel Sandler | 32f6fd5 | 2012-09-06 01:22:59 -0400 | [diff] [blame] | 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; |
Jeff Brown | 11159e9 | 2012-10-11 15:58:37 -0700 | [diff] [blame] | 21 | import android.service.dreams.Sandman; |
Daniel Sandler | 32f6fd5 | 2012-09-06 01:22:59 -0400 | [diff] [blame] | 22 | |
Jeff Brown | 11159e9 | 2012-10-11 15:58:37 -0700 | [diff] [blame] | 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 | */ |
Daniel Sandler | 32f6fd5 | 2012-09-06 01:22:59 -0400 | [diff] [blame] | 30 | public class Somnambulator extends Activity { |
Daniel Sandler | 32f6fd5 | 2012-09-06 01:22:59 -0400 | [diff] [blame] | 31 | public Somnambulator() { |
| 32 | } |
Daniel Sandler | 3a12029 | 2012-09-28 11:28:09 -0400 | [diff] [blame] | 33 | |
Daniel Sandler | 32f6fd5 | 2012-09-06 01:22:59 -0400 | [diff] [blame] | 34 | @Override |
| 35 | public void onStart() { |
| 36 | super.onStart(); |
Jeff Brown | 11159e9 | 2012-10-11 15:58:37 -0700 | [diff] [blame] | 37 | |
Daniel Sandler | 32f6fd5 | 2012-09-06 01:22:59 -0400 | [diff] [blame] | 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, |
Daniel Sandler | b055aa8 | 2012-10-26 15:11:53 -0400 | [diff] [blame] | 46 | Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher_dreams)); |
Daniel Sandler | 32f6fd5 | 2012-09-06 01:22:59 -0400 | [diff] [blame] | 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 { |
Daniel Sandler | 3a12029 | 2012-09-28 11:28:09 -0400 | [diff] [blame] | 51 | boolean docked = launchIntent.hasCategory(Intent.CATEGORY_DESK_DOCK); |
Jeff Brown | 11159e9 | 2012-10-11 15:58:37 -0700 | [diff] [blame] | 52 | if (docked) { |
| 53 | Sandman.startDreamWhenDockedIfAppropriate(this); |
Daniel Sandler | 3a12029 | 2012-09-28 11:28:09 -0400 | [diff] [blame] | 54 | } else { |
Jeff Brown | 11159e9 | 2012-10-11 15:58:37 -0700 | [diff] [blame] | 55 | Sandman.startDreamByUserRequest(this); |
Daniel Sandler | 32f6fd5 | 2012-09-06 01:22:59 -0400 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | finish(); |
| 59 | } |
Daniel Sandler | 32f6fd5 | 2012-09-06 01:22:59 -0400 | [diff] [blame] | 60 | } |