コード例 #1
0
 /** Called when deinitializing component. */
 protected void onDeinitialize() {
   super.onDeinitialize();
   m_FileThread.quitSafely();
   m_DecodeBitmapThread.quitSafely();
   m_FileThread = null;
   m_FileHandler = null;
   m_FileList.clear();
   m_FileObserver.stopWatching();
   m_FileObserver = null;
 }
コード例 #2
0
  /** Called when initializing component. */
  protected void onInitialize() {
    // start file thread
    m_FileThread = new FileManageerThread("save media thread");
    m_FileThread.start();
    m_FileHandler = m_FileThread.getHandler();
    // start image thread
    m_DecodeBitmapThread = new DecodeBitmapThread("decode bitmap thread");
    m_DecodeBitmapThread.start();
    m_DecodeBitmapHandler = m_DecodeBitmapThread.getHandler();
    // observe file change
    m_FileHandler.sendMessage(Message.obtain(m_FileHandler, MESSAGE_LOAD_IMAGES));
    m_FileObserver =
        new FileObserver(m_DefaultFolder.getAbsolutePath()) {

          @Override
          public void onEvent(int event, String file) {
            if (event == FileObserver.DELETE) {
              m_FileHandler.sendMessage(Message.obtain(m_FileHandler, MESSAGE_LOAD_IMAGES, 1, 0));
            }
          }
        };
    m_FileObserver.startWatching(); // START OBSERVING

    /*
     * Creates a work queue for the pool of Thread objects used for
     * decoding, using a linked list queue that blocks when the queue is
     * empty.
     */
    m_DecodeWorkQueue = new LinkedBlockingQueue<Runnable>();
    m_DecodeThreadPool =
        new ThreadPoolExecutor(
            NUMBER_OF_CORES,
            NUMBER_OF_CORES,
            KEEP_ALIVE_TIME,
            KEEP_ALIVE_TIME_UNIT,
            m_DecodeWorkQueue);
  }