/packages/SystemUI/src/com/android/systemui/Somnambulator.java

https://github.com/aizuzi/platform_frameworks_base · Java · 60 lines · 33 code · 5 blank · 22 comment · 4 complexity · 65e4b7dc10b661b6c21672d5353962ae MD5 · raw file

  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.systemui;
  17. import android.app.Activity;
  18. import android.content.Intent;
  19. import android.service.dreams.Sandman;
  20. /**
  21. * A simple activity that launches a dream.
  22. * <p>
  23. * Note: This Activity is special. If this class is moved to another package or
  24. * renamed, be sure to update the component name in {@link Sandman}.
  25. * </p>
  26. */
  27. public class Somnambulator extends Activity {
  28. public Somnambulator() {
  29. }
  30. @Override
  31. public void onStart() {
  32. super.onStart();
  33. final Intent launchIntent = getIntent();
  34. final String action = launchIntent.getAction();
  35. if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
  36. Intent shortcutIntent = new Intent(this, Somnambulator.class);
  37. shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
  38. | Intent.FLAG_ACTIVITY_NEW_TASK);
  39. Intent resultIntent = new Intent();
  40. resultIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
  41. Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher_dreams));
  42. resultIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
  43. resultIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.start_dreams));
  44. setResult(RESULT_OK, resultIntent);
  45. } else {
  46. boolean docked = launchIntent.hasCategory(Intent.CATEGORY_DESK_DOCK);
  47. if (docked) {
  48. Sandman.startDreamWhenDockedIfAppropriate(this);
  49. } else {
  50. Sandman.startDreamByUserRequest(this);
  51. }
  52. }
  53. finish();
  54. }
  55. }