예제 #1
0
  protected void startThumbnailCreation() {
    if (thumbnail_size_perc <= 0) return;
    // Log.i( TAG, "thumbnails " + thumbnail_size_perc );
    String path = getPath(uri, true);
    if (path == null || path.charAt(0) != '/') return;

    if (tht != null) tht.interrupt();

    Handler h =
        new Handler() {
          public void handleMessage(Message msg) {
            notifyDataSetChanged();
          }
        };
    tht = new ThumbnailsThread(this, h, Utils.mbAddSl(path), items);
    tht.start();
  }
예제 #2
0
  public final String getPath(Uri u, boolean dir) {
    try {
      final List<String> paths = u.getPathSegments();
      if (paths.size() < 4) return null;
      String path_part = paths.get(3);
      int col_pos = path_part.lastIndexOf(':');
      String volume, path_root = null, sub_path, full_path;
      volume = paths.get(1);
      sub_path = path_part.substring(col_pos + 1);

      if (volume.startsWith("primary"))
        return Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + sub_path;
      else {
        try {
          File probe;
          volume = volume.substring(0, volume.length() - 1);
          if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            full_path = "/mnt/media_rw/" + volume + "/" + sub_path;
            probe = new File(full_path);
            if (dir ? probe.isDirectory() : probe.isFile()) return full_path;
          } else {
            path_root = Utils.getSecondaryStorage();
            if (path_root != null) {
              full_path = Utils.mbAddSl(path_root) + sub_path;
              probe = new File(full_path);
              if (dir ? probe.isDirectory() : probe.isFile()) return full_path;
            }
          }
        } catch (Exception e) {
        }
        if (path_root == null) path_root = volume; // better than nothing
      }
      return path_root + "/" + sub_path;
    } catch (Exception e) {
      Log.e(TAG, "Can't get the real location of " + u, e);
    }
    return null;
  }