Esempio n. 1
0
 /** Cancel loading of a drawable for a certain ImageView. */
 public void cancelLoad(ImageView view) {
   String fso = mRequests.get(view);
   if (fso != null && mWorkerHandler != null) {
     mWorkerHandler.removeMessages(MSG_LOAD, fso);
   }
   mRequests.remove(view);
 }
Esempio n. 2
0
 public void addEnvToIntent(Intent intent) {
   Map<String, String> envMap = System.getenv();
   Set<Map.Entry<String, String>> envSet = envMap.entrySet();
   Iterator<Map.Entry<String, String>> envIter = envSet.iterator();
   int c = 0;
   while (envIter.hasNext()) {
     Map.Entry<String, String> entry = envIter.next();
     intent.putExtra("env" + c, entry.getKey() + "=" + entry.getValue());
     c++;
   }
 }
Esempio n. 3
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;
            }
          }
        }
Esempio n. 4
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. 5
0
  private void startUpload(int index) {
    if (NavigineApp.Navigation == null) return;

    String userHash = NavigineApp.Settings.getString("user_hash", "");
    if (userHash.length() == 0) return;

    LocationInfo info = mInfoList.get(index);
    String location = new String(info.title);
    Log.d(TAG, String.format(Locale.ENGLISH, "Start upload: %s", location));

    synchronized (mLoaderMap) {
      if (!mLoaderMap.containsKey(location)) {
        LoaderState loader = new LoaderState();
        loader.location = location;
        loader.type = UPLOAD;
        loader.id = LocationLoader.startLocationUploader(location, info.archiveFile, true);
        mLoaderMap.put(location, loader);
      }
    }
    mAdapter.updateList();
  }
Esempio n. 6
0
  private void updateLocationLoaders() {
    if (NavigineApp.Navigation == null) return;

    long timeNow = DateTimeUtils.currentTimeMillis();
    mUpdateLocationLoadersTime = timeNow;

    synchronized (mLoaderMap) {
      Iterator<Map.Entry<String, LoaderState>> iter = mLoaderMap.entrySet().iterator();
      while (iter.hasNext()) {
        Map.Entry<String, LoaderState> entry = iter.next();

        LoaderState loader = entry.getValue();
        if (loader.state < 100) {
          loader.timeLabel = timeNow;
          if (loader.type == DOWNLOAD) loader.state = LocationLoader.checkLocationLoader(loader.id);
          if (loader.type == UPLOAD) loader.state = LocationLoader.checkLocationUploader(loader.id);
        } else if (loader.state == 100) {
          String archivePath = NavigineApp.Navigation.getArchivePath();
          String locationFile =
              LocationLoader.getLocationFile(NavigineApp.AppContext, loader.location);
          if (archivePath != null && archivePath.equals(locationFile)) {
            Log.d(TAG, "Reloading archive " + archivePath);
            if (NavigineApp.Navigation.loadArchive(archivePath)) {
              SharedPreferences.Editor editor = NavigineApp.Settings.edit();
              editor.putString("map_file", archivePath);
              editor.commit();
            }
          }
          if (loader.type == DOWNLOAD) LocationLoader.stopLocationLoader(loader.id);
          if (loader.type == UPLOAD) LocationLoader.stopLocationUploader(loader.id);
          iter.remove();
        } else {
          // Load failed
          if (Math.abs(timeNow - loader.timeLabel) > 5000) {
            if (loader.type == DOWNLOAD) LocationLoader.stopLocationLoader(loader.id);
            if (loader.type == UPLOAD) LocationLoader.stopLocationUploader(loader.id);
            iter.remove();
          }
        }
      }
    }
    updateLocalVersions();
    mAdapter.updateList();
  }
 // # Transformation Contract
 @Override
 public final Bitmap transform(Bitmap source) {
   final Palette palette = Palette.generate(source);
   CACHE.put(source, palette);
   return source;
 }
 public static Palette getPalette(Bitmap bitmap) {
   return CACHE.get(bitmap);
 }