Android Open Source - ImageScanner Scanner Utils






From Project

Back to project page ImageScanner.

License

The source code is released under:

Apache License

If you think the Android project ImageScanner listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.scanner.utils;
//w  ww. j a v  a 2s . c  om
import java.io.File;
import java.util.ArrayList;

import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.provider.MediaStore.Images.Media;

import com.scanner.beans.GalleryFolderBean;



public class ScannerUtils {

  /**
   * 
   * get the folders which contain picture files;
   */
  public static ArrayList<GalleryFolderBean> getGalleryFolder(Context context) {
    ArrayList<GalleryFolderBean> list = new ArrayList<GalleryFolderBean>();
    ArrayList<String> folderList = new ArrayList<String>();
    Bitmap bitmap;
    String folderName;
    String folderSize = "";
    Cursor cursor = context.getContentResolver().query(
        Media.EXTERNAL_CONTENT_URI, null, null, null, null);

    while (cursor.moveToNext()) {
      byte[] data = cursor.getBlob(cursor.getColumnIndex(Media.DATA));
      String imgUrl = new String(data, 0, data.length - 1);
      // localImageList.add(new LocalImageBean(path));
      File file = new File(imgUrl);
      folderName = file.getParentFile().getName();
      if (false == folderList.contains(folderName)) {
        String folderPath = file.getParentFile().getAbsolutePath();
        folderSize = getGalleryBitmapsIn_A_Folder(folderPath).size() + "";
        folderList.add(folderName);
        Bitmap bitmap_decode = BitmapUtils.decodeBitmapFromFile(imgUrl,
            100, 100);
        bitmap = BitmapUtils.centerSquareScaleBitmap(bitmap_decode, 70);
        GalleryFolderBean bean = new GalleryFolderBean(bitmap,
            folderName, file.getParentFile().getAbsolutePath(), folderSize);        
        list.add(bean);
      }
    }
    return list;
  }
  
  
  /**
   * get all the pictures in a certain folder
   * @param path
   * @return
   */
  public static ArrayList<String> getGalleryBitmapsIn_A_Folder(String path) {
    ArrayList<String> list = new ArrayList<String>();
    String tempPath;
    File file = new File(path);
    for (File imgFile : file.listFiles()) {
      tempPath = imgFile.getAbsolutePath();
      if(isImgFile(tempPath))
        list.add(0,tempPath);
    }
    
    return list;
  }
  
  /**
   * check if it is a picture file
   * @param name
   * @return
   */
  public static boolean isImgFile(String name){
    if(name.endsWith("jpg") || name.endsWith("jpeg") || name.endsWith("png") || name.endsWith("icon")){
      return true;
    }
    return false;
  }

}




Java Source Code List

com.atermenji.android.iconicdroid.IconicFontDrawable.java
com.atermenji.android.iconicdroid.icon.EntypoIcon.java
com.atermenji.android.iconicdroid.icon.EntypoSocialIcon.java
com.atermenji.android.iconicdroid.icon.FontAwesomeIcon.java
com.atermenji.android.iconicdroid.icon.Icon.java
com.atermenji.android.iconicdroid.icon.IconicIcon.java
com.atermenji.android.iconicdroid.util.TypefaceManager.java
com.example.imagescanner.GalleryFolderActivity.java
com.example.imagescanner.GalleryGridActivity.java
com.example.imagescanner.MainActivity.java
com.scanner.adapter.GalleryFolderListAdapter.java
com.scanner.adapter.GalleryGridAdapter.java
com.scanner.beans.GalleryFolderBean.java
com.scanner.beans.GridImageBean.java
com.scanner.utils.BitmapUtils.java
com.scanner.utils.ConstantsUtils.java
com.scanner.utils.DensityUtil.java
com.scanner.utils.FormatBitmapUtils.java
com.scanner.utils.ImageLoaderCacheHelper.java
com.scanner.utils.L.java
com.scanner.utils.ScannerUtils.java
com.scanner.utils.UIHelper.java