Esempio n. 1
0
  /**
   * Method that returns a drawable reference of a FileSystemObject.
   *
   * @param iconView View to load the drawable into
   * @param fso The FileSystemObject reference
   * @param defaultIcon Drawable to be used in case no specific one could be found
   * @return Drawable The drawable reference
   */
  public void loadDrawable(ImageView iconView, final String fso, Drawable defaultIcon) {
    if (!mUseThumbs) {
      return;
    }

    // Is cached?
    final String filePath = fso;
    if (this.mAppIcons.containsKey(filePath)) {
      iconView.setImageBitmap(this.mAppIcons.get(filePath));
      return;
    }
    mRequests.put(iconView, fso);
    new Thread(
            new Runnable() {
              @Override
              public void run() {

                mHandler.removeMessages(MSG_DESTROY);
                if (mWorkerThread == null || mWorkerHandler == null) {
                  mWorkerThread = new HandlerThread("IconHolderLoader");
                  mWorkerThread.start();
                  mWorkerHandler = new WorkerHandler(mWorkerThread.getLooper());
                }
                Message msg = mWorkerHandler.obtainMessage(MSG_LOAD, fso);
                msg.sendToTarget();
              }
            })
        .start();
  }
Esempio n. 2
0
        private void processResult(LoadResult result) {
          // Cache the new drawable
          final String filePath = (result.fso);
          mAppIcons.put(filePath, result.result);

          // find the request for it
          for (Map.Entry<ImageView, String> entry : mRequests.entrySet()) {
            final ImageView imageView = entry.getKey();
            final String fso = entry.getValue();
            if (fso == result.fso) {
              imageView.setImageBitmap(result.result);
              mRequests.remove(imageView);
              break;
            }
          }
        }