Esempio n. 1
0
 private Category makeCategory(FileInfo file, int type) {
   Category category = new Category();
   switch (type) {
     case TYPE_IMAGE:
       category.filePath = file.filePath;
       category.alias = ((ImageFile) file).bucketName;
       break;
     case TYPE_AUDIO:
       category.alias = ((AudioFile) file).album;
       category.filePath = ((AudioFile) file).album;
       break;
     case TYPE_VIDEO:
       category.filePath = file.filePath;
       break;
   }
   category.uri = category.filePath;
   category.init();
   category.addFile(file);
   return category;
 }
Esempio n. 2
0
  public synchronized void initImage() {
    if (null == mImageCategory) {
      mImageCategory = new ConcurrentHashMap<String, Category>();
    }
    mImageCategory.clear();

    String volumeName = "external";
    Uri uri = Images.Media.getContentUri(volumeName);
    String[] columns =
        new String[] {
          BaseColumns._ID,
          MediaColumns.DATA,
          MediaColumns.DISPLAY_NAME,
          MediaColumns.SIZE,
          MediaColumns.DATE_ADDED,
          MediaColumns.DATE_MODIFIED,
          ImageColumns.BUCKET_DISPLAY_NAME,
          MediaColumns.MIME_TYPE
        };
    Cursor cur = null;
    try {
      cur =
          mContext
              .getContentResolver()
              .query(uri, columns, buildSelectionByCategory(TYPE_IMAGE), null, null);
      if (cur == null) {
        return;
      }

      if (!cur.moveToFirst()) {
        return;
      }

      do {
        ImageFile file = ImageFile.getInfo(cur);
        if (null == file) {
          continue;
        }
        // 取一张图片的路径,add by yangbing
        //				if (MediaOpenSettingConstants.sImagePath == null) {
        //					if (file.fullFilePath != null && !"".equals(file.fullFilePath)) {
        //						MediaOpenSettingConstants.sImagePath = file.fullFilePath;
        //					}
        //				}
        if (mImageCategory.containsKey(file.filePath)) {
          Category category = mImageCategory.get(file.filePath);
          category.addFile(file);
        } else {
          Category category = new Category();
          category.filePath = file.filePath;
          category.uri = category.filePath;
          category.alias = file.bucketName;
          category.init();
          category.addFile(file);
          mImageCategory.put(file.filePath, category);
        }
      } while (cur.moveToNext());
    } catch (SQLiteException e) {
      Log.e("FileEngine", "init image error");
    } finally {
      if (cur != null) {
        cur.close();
      }
    }
  }
Esempio n. 3
0
  public synchronized void initVideo() {
    if (null == mVideoCategory) {
      mVideoCategory = new ConcurrentHashMap<String, Category>();
    }
    mVideoCategory.clear();

    String volumeName = "external";
    Uri uri = Video.Media.getContentUri(volumeName);

    String[] columns =
        new String[] {
          BaseColumns._ID,
          MediaColumns.DATA,
          MediaColumns.DISPLAY_NAME,
          MediaColumns.SIZE,
          MediaColumns.DATE_ADDED,
          MediaColumns.DATE_MODIFIED,
          VideoColumns.DURATION,
          MediaColumns.MIME_TYPE
        };
    Cursor cur = null;
    try {
      cur =
          mContext
              .getContentResolver()
              .query(uri, columns, buildSelectionByCategory(TYPE_AUDIO), null, null);

      if (cur == null) {
        return;
      }

      if (!cur.moveToFirst()) {
        return;
      }

      do {
        VideoFile file = VideoFile.getInfo(cur);
        if (null == file) {
          continue;
        }

        if (mVideoCategory.containsKey(file.filePath)) {
          Category category = mVideoCategory.get(file.filePath);
          category.addFile(file);
        } else {
          Category category = new Category();
          category.filePath = file.filePath;
          category.uri = category.filePath;
          category.init();
          category.addFile(file);
          mVideoCategory.put(file.filePath, category);
        }
      } while (cur.moveToNext());
    } catch (SQLiteException e) {
      Log.e("FileEngine", "init video error");
    } finally {
      if (cur != null) {
        cur.close();
      }
    }
  }
Esempio n. 4
0
  public synchronized void initAudio() {
    if (null == mAudioCategory) {
      mAudioCategory = new ConcurrentHashMap<String, Category>();
    }
    mAudioCategory.clear();
    Uri uri = Audio.Media.EXTERNAL_CONTENT_URI;

    String[] columns =
        new String[] {
          BaseColumns._ID,
          MediaColumns.DATA,
          MediaColumns.DISPLAY_NAME,
          MediaColumns.SIZE,
          MediaColumns.DATE_ADDED,
          MediaColumns.DATE_MODIFIED,
          AudioColumns.DURATION,
          AudioColumns.ARTIST,
          AudioColumns.ALBUM,
          AudioColumns.ALBUM_ID,
          MediaColumns.MIME_TYPE,
          MediaColumns.TITLE
        };

    Cursor cur = null;
    try {
      cur =
          mContext
              .getContentResolver()
              .query(uri, columns, buildSelectionByCategory(TYPE_AUDIO), null, null);
      if (cur == null) {
        return;
      }

      if (!cur.moveToFirst()) {
        return;
      }

      do {
        AudioFile file = AudioFile.getInfo(cur);
        if (null == file) {
          continue;
        }
        // 取一首歌曲的路径,add by yangbing
        //				if (MediaOpenSettingConstants.sMusicPath == null) {
        //					if (file.fullFilePath != null && !"".equals(file.fullFilePath)) {
        //						MediaOpenSettingConstants.sMusicPath = file.fullFilePath;
        //					}
        //				}
        if (mAudioCategory.containsKey(file.album)) {
          Category category = mAudioCategory.get(file.album);
          category.addFile(file);
        } else {
          Category category = new Category();
          category.filePath = file.album;
          category.uri = category.filePath;
          category.alias = file.album;
          category.addFile(file);
          mAudioCategory.put(category.filePath, category);
        }
      } while (cur.moveToNext());
    } catch (SQLiteException e) {
      Log.e("FileEngine", "init audio error");
    } finally {
      if (cur != null) {
        cur.close();
      }
    }
  }