Android Open Source - Resonos-Android-Framework Lifecycle Task Queue






From Project

Back to project page Resonos-Android-Framework.

License

The source code is released under:

Apache License

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

package com.resonos.apps.library.util;
/*from   w w w.  j a  v  a2s. c  o m*/
import java.util.ArrayList;

/**
 * This class manages a task queue of events to be run at discrete times.
 * @author Chris
 */
public class LifecycleTaskQueue {
  
  /**
   * This class represents a task to be run once after an event.
   */
  private class LifecycleTask {
    private Runnable _task;
    private Enum<?> _event;
    
    /**
     * Create the task
     * @param task : a runnable representing the action
     * @param event : an enum representing the trigger event
     */
    public LifecycleTask(Runnable task, Enum<?> event) {
      _task = task;
      _event = event;
    }
    
    /**
     * Determines if an event matches this task's trigger
     * @param event : the event
     * @return true if it matches
     */
    public boolean matches(Enum<?> event) {
      return _event.equals(event);
    }
    
    /**
     * Run this task's runnable.
     */
    public void run() {
      _task.run();
    }
  }

  private ArrayList<LifecycleTask> mQueuedTasks = new ArrayList<LifecycleTask>();
  private ArrayList<LifecycleTask> tTasks = new ArrayList<LifecycleTask>();
  
  /**
   * Add a task to run once after an event.
   * @param event : an enum tagging the event
   * @param task : the task to be run
   */
  public void addTask(Enum<?> event, Runnable task) {
    mQueuedTasks.add(new LifecycleTask(task, event));
  }
  
  /**
   * Run all tasks that have been queued for a certain event.
   * @param event : the event that has occurred
   */
  public void runEvent(Enum<?> event) {
    tTasks.clear();
    LifecycleTask t;
    for (int i = 0; i < mQueuedTasks.size(); i++) {
      t = mQueuedTasks.get(i);
      if (t.matches(event))
        t.run();
      else
        tTasks.add(t);
    }
    mQueuedTasks.clear();
    mQueuedTasks.addAll(tTasks);
  }

  /**
   * Clear all pending tasks.
   */
  public void empty() {
    mQueuedTasks.clear();
    tTasks.clear();
  }
}




Java Source Code List

com.resonos.apps.library.Action.java
com.resonos.apps.library.AlertFragment.java
com.resonos.apps.library.App.java
com.resonos.apps.library.BaseFragment.java
com.resonos.apps.library.FragmentBaseActivity.java
com.resonos.apps.library.file.AltAndroidFileHandle.java
com.resonos.apps.library.file.AltAndroidFiles.java
com.resonos.apps.library.file.AltFileHandle.java
com.resonos.apps.library.file.FileCache.java
com.resonos.apps.library.media.AudioVisualizer.java
com.resonos.apps.library.media.BitmapMemoryCache.java
com.resonos.apps.library.media.HueColorFilter.java
com.resonos.apps.library.media.ImageLoader.java
com.resonos.apps.library.media.MediaScannerNotifier.java
com.resonos.apps.library.model.Coord.java
com.resonos.apps.library.model.ImmutableCoord.java
com.resonos.apps.library.tabviewpager.CustomViewPager.java
com.resonos.apps.library.tabviewpager.PageIndicator.java
com.resonos.apps.library.tabviewpager.TabPageIndicator.java
com.resonos.apps.library.tabviewpager.TabViewPagerAdapter.java
com.resonos.apps.library.tabviewpager.TabViewPagerFragment.java
com.resonos.apps.library.tabviewpager.TitleProvider.java
com.resonos.apps.library.util.AppUtils.java
com.resonos.apps.library.util.ErrorReporter.java
com.resonos.apps.library.util.LifecycleTaskQueue.java
com.resonos.apps.library.util.M.java
com.resonos.apps.library.util.NetworkClient.java
com.resonos.apps.library.util.NetworkRequest.java
com.resonos.apps.library.util.ParameterList.java
com.resonos.apps.library.util.SensorReader.java
com.resonos.apps.library.util.TouchViewWorker.java
com.resonos.apps.library.util.ViewServer.java
com.resonos.apps.library.widget.DashboardLayout.java
com.resonos.apps.library.widget.FormBuilder.java
com.resonos.apps.library.widget.FormElement.java
com.resonos.apps.library.widget.ListFormBuilder.java
com.resonos.apps.library.widget.PopupWindows3D.java
com.resonos.apps.library.widget.QuickAction3D.java
com.resonos.apps.library.widget.RangeSeekBar.java
com.resonos.apps.library.widget.SeekBar.java
com.resonos.apps.library.widget.ToolBarButton.java
com.resonos.apps.library.widget.ToolBar.java