Android Open Source - TaskButler Wakeful Intent Service






From Project

Back to project page TaskButler.

License

The source code is released under:

GNU General Public License

If you think the Android project TaskButler listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * WakeFulIntentService.java// w  ww  .  j  a  v  a  2  s.  c om
 * 
 * Copyright 2012 Jonathan Hasenzahl, James Celona, Dhimitraq Jorgji
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package edu.worcester.cs499summer2012.service;

import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;

/**
 * Acquires a partial WakeLock, allows TaskButtlerService to keep the CPU alive
 * until the work is done.
 * @author Dhimitraq Jorgji
 *
 */
public class WakefulIntentService extends IntentService {
  public static final String
  LOCK_NAME_STATIC="edu.worcester.cs499summer2012.TaskButlerService.Static";
  public static final String
  LOCK_NAME_LOCAL="edu.worcester.cs499summer2012.TaskButlerService.Local";
  private static PowerManager.WakeLock lockStatic=null;
  private PowerManager.WakeLock lockLocal=null;

  public WakefulIntentService(String name) {
    super(name);
  }
  /**
   * Acquire a partial static WakeLock, you need too call this within the class
   * that calls startService()
   * @param context
   */
  public static void acquireStaticLock(Context context) {
    getLock(context).acquire();
  }

  synchronized private static PowerManager.WakeLock getLock(Context context) {
    if (lockStatic==null) {
      PowerManager
      mgr=(PowerManager)context.getSystemService(Context.POWER_SERVICE);
      lockStatic=mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
          LOCK_NAME_STATIC);
      lockStatic.setReferenceCounted(true);
    }
    return(lockStatic);
  }
  
  @Override
  public void onCreate() {
    super.onCreate();
    PowerManager mgr=(PowerManager)getSystemService(Context.POWER_SERVICE);
    lockLocal=mgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
        LOCK_NAME_LOCAL);
    lockLocal.setReferenceCounted(true);
  }

  @Override
  public void onStart(Intent intent, final int startId) {
    lockLocal.acquire();
    super.onStart(intent, startId);
    getLock(this).release();
  }

  @Override
  protected void onHandleIntent(Intent intent) {
    lockLocal.release();
  }
}




Java Source Code List

edu.worcester.cs499summer2012.activity.AddTaskActivity.java
edu.worcester.cs499summer2012.activity.BaseTaskActivity.java
edu.worcester.cs499summer2012.activity.CustomSortActivity.java
edu.worcester.cs499summer2012.activity.EditCategoriesActivity.java
edu.worcester.cs499summer2012.activity.EditTaskActivity.java
edu.worcester.cs499summer2012.activity.MainActivity.java
edu.worcester.cs499summer2012.activity.SettingsActivity.java
edu.worcester.cs499summer2012.activity.ViewTaskActivity.java
edu.worcester.cs499summer2012.adapter.CategoryListAdapter.java
edu.worcester.cs499summer2012.adapter.ComparatorListAdapter.java
edu.worcester.cs499summer2012.adapter.PriorityListAdapter.java
edu.worcester.cs499summer2012.adapter.TaskListAdapter.java
edu.worcester.cs499summer2012.comparator.TaskAutoComparator.java
edu.worcester.cs499summer2012.comparator.TaskCategoryComparator.java
edu.worcester.cs499summer2012.comparator.TaskCompletionComparator.java
edu.worcester.cs499summer2012.comparator.TaskDateCreatedComparator.java
edu.worcester.cs499summer2012.comparator.TaskDateDueComparator.java
edu.worcester.cs499summer2012.comparator.TaskDateModifiedComparator.java
edu.worcester.cs499summer2012.comparator.TaskNameComparator.java
edu.worcester.cs499summer2012.comparator.TaskPriorityComparator.java
edu.worcester.cs499summer2012.database.DatabaseHandler.java
edu.worcester.cs499summer2012.database.TasksDataSource.java
edu.worcester.cs499summer2012.service.NotificationHelper.java
edu.worcester.cs499summer2012.service.OnAlarmReceiver.java
edu.worcester.cs499summer2012.service.OnBootReceiver.java
edu.worcester.cs499summer2012.service.TaskAlarm.java
edu.worcester.cs499summer2012.service.TaskButlerService.java
edu.worcester.cs499summer2012.service.TaskButlerWidgetProvider.java
edu.worcester.cs499summer2012.service.WakefulIntentService.java
edu.worcester.cs499summer2012.task.BackupManager.java
edu.worcester.cs499summer2012.task.Category.java
edu.worcester.cs499summer2012.task.Comparator.java
edu.worcester.cs499summer2012.task.Task.java
edu.worcester.cs499summer2012.task.ToastMaker.java