Ejemplo n.º 1
0
  /** 得到缩略图 */
  private void getThumbnail() {
    /** 临时的辅助类,用于防止同一个文件夹的多次扫描 */
    HashMap<String, Integer> tmpDir = new HashMap<String, Integer>();

    Cursor mCursor =
        getContentResolver()
            .query(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                new String[] {MediaStore.Images.ImageColumns.DATA},
                "",
                null,
                MediaStore.MediaColumns.DATE_ADDED + " DESC");
    Log.e("TAG", mCursor.getCount() + "");
    if (mCursor.moveToFirst()) {
      do {
        // 获取图片的路径
        String path = mCursor.getString(0);
        Log.e("TAG", path);
        imageAll.images.add(new ImageItem(path));
        // 获取该图片的父路径名
        File parentFile = new File(path).getParentFile();
        if (parentFile == null) {
          continue;
        }
        Floder imageFloder = null;
        String dirPath = parentFile.getAbsolutePath();
        if (!tmpDir.containsKey(dirPath)) {
          // 初始化imageFloder
          imageFloder = new Floder();
          imageFloder.setDir(dirPath);
          imageFloder.setFirstImagePath(path);
          mDirPaths.add(imageFloder);
          Log.d("zyh", dirPath + "," + path);
          tmpDir.put(dirPath, mDirPaths.indexOf(imageFloder));
        } else {
          imageFloder = mDirPaths.get(tmpDir.get(dirPath));
        }
        imageFloder.images.add(new ImageItem(path));
      } while (mCursor.moveToNext());
    }
    mCursor.close();
    for (int i = 0; i < mDirPaths.size(); i++) {
      Floder f = mDirPaths.get(i);
      Log.d("zyh", i + "-----" + f.getName() + "---" + f.images.size());
    }
    tmpDir = null;
  }