Android Open Source - SDCardTrac Alarm Helper






From Project

Back to project page SDCardTrac.

License

The source code is released under:

GNU General Public License

If you think the Android project SDCardTrac 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

/*
 * SDCardTrac application - keeps track of the /sdcard usage
 * Copyright (C) 2012 Narendra M.A./*from w w w  . j a  va2  s.  co m*/
*/

package com.nma.util.sdcardtrac;

import java.util.Calendar;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

// Class to encapsulate AlarmManager calls

public class AlarmHelper {
  private Context ctx;
  // Alarms
  PendingIntent alarmIntent;
    
  public AlarmHelper(Context c) {
    ctx = c;
        alarmIntent = null;
  }
  
    // Setup recurring collection of events
    public boolean manageAlarm(boolean enable, boolean alarmSetupWasDone, int startOffset, long triggerInterval) {
      boolean alarmSetupDone = false;

        if (alarmIntent == null) {
            Intent triggerIntent = new Intent(ctx, DeltaCompute.class);
            alarmIntent = PendingIntent.getBroadcast(ctx, 0, triggerIntent, 0);
        }

      if (enable) {
        if (alarmSetupWasDone) {
          ((AlarmManager)ctx.getSystemService(Context.ALARM_SERVICE)).cancel(alarmIntent);
        }
            // Setup the alarm
            setupAlarm(startOffset, triggerInterval);
      alarmSetupDone = true;
      } else if (alarmSetupWasDone) {
      ((AlarmManager)ctx.getSystemService(Context.ALARM_SERVICE)).cancel(alarmIntent);
      Log.d(getClass().getName(), "Cancelling alarms");
      alarmSetupDone = false;
      }
      
      return alarmSetupDone;
    }
    
    // Alarm setup
    private void setupAlarm(int startOffset, long triggerInterval) {
      Log.d(this.getClass().getName(), "Setting up alarm for collection");

        AlarmManager alarmEr = (AlarmManager)ctx.getSystemService(Context.ALARM_SERVICE);
      Calendar time = Calendar.getInstance();
      time.setTimeInMillis(System.currentTimeMillis());
      time.add(Calendar.SECOND, startOffset);
      alarmEr.setInexactRepeating(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), 
          triggerInterval, alarmIntent); //AlarmManager.INTERVAL_FIFTEEN_MINUTES
      Log.d(this.getClass().getName(), "Done with alarm setup: " + triggerInterval);
    }
}




Java Source Code List

com.jjoe64.graphview.BarGraphView.java
com.jjoe64.graphview.CustomLabelFormatter.java
com.jjoe64.graphview.GraphViewDataInterface.java
com.jjoe64.graphview.GraphViewSeries.java
com.jjoe64.graphview.GraphViewStyle.java
com.jjoe64.graphview.GraphView.java
com.jjoe64.graphview.LineGraphView.java
com.jjoe64.graphview.ValueDependentColor.java
com.jjoe64.graphview.compatible.RealScaleGestureDetector.java
com.jjoe64.graphview.compatible.ScaleGestureDetector.java
com.nma.util.sdcardtrac.AlarmHelper.java
com.nma.util.sdcardtrac.BitcoinIntegration.java
com.nma.util.sdcardtrac.ChangeLogFragment.java
com.nma.util.sdcardtrac.DatabaseLoader.java
com.nma.util.sdcardtrac.DatabaseManager.java
com.nma.util.sdcardtrac.DeleteDataPreference.java
com.nma.util.sdcardtrac.DeltaCompute.java
com.nma.util.sdcardtrac.FileObserverService.java
com.nma.util.sdcardtrac.GraphActivity.java
com.nma.util.sdcardtrac.GraphFragment.java
com.nma.util.sdcardtrac.GraphTabListener.java
com.nma.util.sdcardtrac.HelpFragment.java
com.nma.util.sdcardtrac.MyExpandableListAdapter.java
com.nma.util.sdcardtrac.SQLiteHelper.java
com.nma.util.sdcardtrac.SearchableActivity.java
com.nma.util.sdcardtrac.SettingsActivity.java
com.nma.util.sdcardtrac.StorageHelper.java
com.nma.util.sdcardtrac.UsageFileObserver.java