Android Open Source - Roundr Window Cache






From Project

Back to project page Roundr.

License

The source code is released under:

Copyright (C) 2013 Mohammad Adib Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the te...

If you think the Android project Roundr 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 wei.mark.standout;
/*from w  w  w.  ja  v a2 s. co m*/
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import wei.mark.standout.ui.Window;

import android.util.SparseArray;

public class WindowCache {
  public Map<Class<? extends StandOutWindow>, SparseArray<Window>> sWindows;

  public WindowCache() {
    sWindows = new HashMap<Class<? extends StandOutWindow>, SparseArray<Window>>();
  }

  /**
   * Returns whether the window corresponding to the class and id exists in
   * the {@link #sWindows} cache.
   * 
   * @param id
   *            The id representing the window.
   * @param cls
   *            Class corresponding to the window.
   * @return True if the window corresponding to the class and id exists in
   *         the cache, or false if it does not exist.
   */
  public boolean isCached(int id, Class<? extends StandOutWindow> cls) {
    return getCache(id, cls) != null;
  }

  /**
   * Returns the window corresponding to the id from the {@link #sWindows}
   * cache.
   * 
   * @param id
   *            The id representing the window.
   * @param cls
   *            The class of the implementation of the window.
   * @return The window corresponding to the id if it exists in the cache, or
   *         null if it does not.
   */
  public Window getCache(int id, Class<? extends StandOutWindow> cls) {
    SparseArray<Window> l2 = sWindows.get(cls);
    if (l2 == null) {
      return null;
    }

    return l2.get(id);
  }

  /**
   * Add the window corresponding to the id in the {@link #sWindows} cache.
   * 
   * @param id
   *            The id representing the window.
   * @param cls
   *            The class of the implementation of the window.
   * @param window
   *            The window to be put in the cache.
   */
  public void putCache(int id, Class<? extends StandOutWindow> cls, Window window) {
    SparseArray<Window> l2 = sWindows.get(cls);
    if (l2 == null) {
      l2 = new SparseArray<Window>();
      sWindows.put(cls, l2);
    }

    l2.put(id, window);
  }

  /**
   * Remove the window corresponding to the id from the {@link #sWindows}
   * cache.
   * 
   * @param id
   *            The id representing the window.
   * @param cls
   *            The class of the implementation of the window.
   */
  public void removeCache(int id, Class<? extends StandOutWindow> cls) {
    SparseArray<Window> l2 = sWindows.get(cls);
    if (l2 != null) {
      l2.remove(id);
      if (l2.size() == 0) {
        sWindows.remove(cls);
      }
    }
  }

  /**
   * Returns the size of the {@link #sWindows} cache.
   * 
   * @return True if the cache corresponding to this class is empty, false if
   *         it is not empty.
   * @param cls
   *            The class of the implementation of the window.
   */
  public int getCacheSize(Class<? extends StandOutWindow> cls) {
    SparseArray<Window> l2 = sWindows.get(cls);
    if (l2 == null) {
      return 0;
    }

    return l2.size();
  }

  /**
   * Returns the ids in the {@link #sWindows} cache.
   * 
   * @param cls
   *            The class of the implementation of the window.
   * @return The ids representing the cached windows.
   */
  public Set<Integer> getCacheIds(Class<? extends StandOutWindow> cls) {
    SparseArray<Window> l2 = sWindows.get(cls);
    if (l2 == null) {
      return new HashSet<Integer>();
    }

    Set<Integer> keys = new HashSet<Integer>();
    for (int i = 0; i < l2.size(); i++) {
      keys.add(l2.keyAt(i));
    }
    return keys;
  }
  
  public int size() {
    return sWindows.size();
  }
}




Java Source Code List

mohammad.adib.roundr.BootReceiver.java
mohammad.adib.roundr.Corner.java
mohammad.adib.roundr.MainActivity.java
mohammad.adib.roundr.SeekBarPreference.java
mohammad.adib.roundr.SettingsActivity.java
wei.mark.standout.StandOutWindow.java
wei.mark.standout.Utils.java
wei.mark.standout.WindowCache.java
wei.mark.standout.constants.StandOutFlags.java
wei.mark.standout.ui.TouchInfo.java
wei.mark.standout.ui.Window.java