fork download
  1. public int onStartCommand(Intent intent, int flags, int start_id) {
  2. if (null == intent) {
  3. LOGD("service restart");
  4.  
  5. loadScreenState();
  6. return START_STICKY;
  7. }
  8.  
  9. if (intent.getBooleanExtra(AppWidgetManager.ACTION_APPWIDGET_UPDATE, false)) {
  10. LOGD("widget added to home");
  11.  
  12. int[] widget_ids = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
  13.  
  14. switch (mScreenState) {
  15. case NORMAL:
  16. updateWidgets(widget_ids, R.drawable.normal);
  17. break;
  18. case DIM:
  19. updateWidgets(widget_ids, R.drawable.dim);
  20. break;
  21. case BRIGHT:
  22. updateWidgets(widget_ids, R.drawable.bright);
  23. break;
  24. default:
  25. }
  26. } else if (intent.getBooleanExtra(AppWidgetManager.ACTION_APPWIDGET_DISABLED, false)) {
  27. LOGD("widgets ALL removed from home");
  28.  
  29. setScreenState(PowerManager.PARTIAL_WAKE_LOCK, NORMAL);
  30. stopSelf(start_id);
  31.  
  32. // Since all widgets are removed from home, we don't need the service
  33. // keep running any more.
  34. return START_NOT_STICKY;
  35. } else {
  36. // This is a click event
  37. int widget_id = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
  38.  
  39. if (-1 != widget_id) {
  40. switch (mScreenState) {
  41. case NORMAL:
  42. setScreenState(PowerManager.SCREEN_DIM_WAKE_LOCK, DIM);
  43. updateAllWidgets(R.drawable.dim);
  44. break;
  45. case DIM:
  46. setScreenState(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, BRIGHT);
  47. updateAllWidgets(R.drawable.bright);
  48. break;
  49. case BRIGHT:
  50. setScreenState(PowerManager.PARTIAL_WAKE_LOCK, NORMAL);
  51. updateAllWidgets(R.drawable.normal);
  52. break;
  53. default:
  54. }
  55.  
  56. saveScreenState(mScreenState);
  57. } else {
  58. // This should not happen
  59. LOGD("receive click event without widget id");
  60. }
  61. }
  62.  
  63. // We want this service to continue running until it is explicitly
  64. // stopped, so return sticky.
  65. return START_STICKY;
  66. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty