Search in sources :

Example 1 with PhotoItem

use of com.stickercamera.app.model.PhotoItem in project StickerCamera by Skykai521.

the class FileUtils method findPicsInDir.

//获取path路径下的图片
public ArrayList<PhotoItem> findPicsInDir(String path) {
    ArrayList<PhotoItem> photos = new ArrayList<PhotoItem>();
    File dir = new File(path);
    if (dir.exists() && dir.isDirectory()) {
        for (File file : dir.listFiles(new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                String filePath = pathname.getAbsolutePath();
                return (filePath.endsWith(".png") || filePath.endsWith(".jpg") || filePath.endsWith(".jepg"));
            }
        })) {
            photos.add(new PhotoItem(file.getAbsolutePath(), file.lastModified()));
        }
    }
    Collections.sort(photos);
    return photos;
}
Also used : PhotoItem(com.stickercamera.app.model.PhotoItem) ArrayList(java.util.ArrayList) FileFilter(java.io.FileFilter) File(java.io.File)

Example 2 with PhotoItem

use of com.stickercamera.app.model.PhotoItem in project StickerCamera by Skykai521.

the class ImageUtils method findGalleries.

public static Map<String, Album> findGalleries(Context mContext, List<String> paths, long babyId) {
    paths.clear();
    paths.add(FileUtils.getInst().getSystemPhotoPath());
    String[] projection = { MediaStore.Images.Media._ID, MediaStore.Images.Media.DATA, //FIXME 拍照时间为新增照片时间
    MediaStore.Images.Media.DATE_ADDED };
    Cursor cursor = mContext.getContentResolver().query(//指定所要查询的字段
    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, //指定所要查询的字段
    projection, //查询条件
    MediaStore.Images.Media.SIZE + ">?", //查询条件中问号对应的值
    new String[] { "100000" }, MediaStore.Images.Media.DATE_ADDED + " desc");
    cursor.moveToFirst();
    //文件夹照片
    Map<String, Album> galleries = new HashMap<String, Album>();
    while (cursor.moveToNext()) {
        String data = cursor.getString(1);
        if (data.lastIndexOf("/") < 1) {
            continue;
        }
        String sub = data.substring(0, data.lastIndexOf("/"));
        if (!galleries.keySet().contains(sub)) {
            String name = sub.substring(sub.lastIndexOf("/") + 1, sub.length());
            if (!paths.contains(sub)) {
                paths.add(sub);
            }
            galleries.put(sub, new Album(name, sub, new ArrayList<PhotoItem>()));
        }
        galleries.get(sub).getPhotos().add(new PhotoItem(data, (long) (cursor.getInt(2)) * 1000));
    }
    //系统相机照片
    ArrayList<PhotoItem> sysPhotos = FileUtils.getInst().findPicsInDir(FileUtils.getInst().getSystemPhotoPath());
    if (!sysPhotos.isEmpty()) {
        galleries.put(FileUtils.getInst().getSystemPhotoPath(), new Album("胶卷相册", FileUtils.getInst().getSystemPhotoPath(), sysPhotos));
    } else {
        galleries.remove(FileUtils.getInst().getSystemPhotoPath());
        paths.remove(FileUtils.getInst().getSystemPhotoPath());
    }
    return galleries;
}
Also used : PhotoItem(com.stickercamera.app.model.PhotoItem) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Album(com.stickercamera.app.model.Album) Cursor(android.database.Cursor)

Example 3 with PhotoItem

use of com.stickercamera.app.model.PhotoItem in project StickerCamera by Skykai521.

the class AlbumFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View root = inflater.inflate(R.layout.fragment_album, null);
    photos = (ArrayList<PhotoItem>) getArguments().getSerializable("photos");
    albums = (GridView) root.findViewById(R.id.albums);
    albums.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            PhotoItem photo = photos.get(arg2);
            CameraManager.getInst().processPhotoItem(getActivity(), photo);
        }
    });
    return root;
}
Also used : PhotoItem(com.stickercamera.app.model.PhotoItem) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 4 with PhotoItem

use of com.stickercamera.app.model.PhotoItem in project StickerCamera by Skykai521.

the class CameraActivity method addPhoto.

private void addPhoto(PhotoItem photoItem) {
    ImageView photo = new ImageView(this);
    if (StringUtils.isNotBlank(photoItem.getImageUri())) {
        ImageLoaderUtils.displayLocalImage(photoItem.getImageUri(), photo, null);
    } else {
        photo.setImageResource(R.drawable.default_img);
    }
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(photoWidth, photoWidth);
    params.leftMargin = photoMargin;
    params.rightMargin = photoMargin;
    params.gravity = Gravity.CENTER;
    photo.setScaleType(ImageView.ScaleType.CENTER_CROP);
    photo.setTag(photoItem.getImageUri());
    if (photoArea.getChildCount() >= photoNumber) {
        photoArea.removeViewAt(photoArea.getChildCount() - 1);
        photoArea.addView(photo, 0, params);
    } else {
        photoArea.addView(photo, 0, params);
    }
    photo.setOnClickListener(v -> {
        if (v instanceof ImageView && v.getTag() instanceof String) {
            CameraManager.getInst().processPhotoItem(CameraActivity.this, new PhotoItem((String) v.getTag(), System.currentTimeMillis()));
        }
    });
}
Also used : PhotoItem(com.stickercamera.app.model.PhotoItem) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout)

Example 5 with PhotoItem

use of com.stickercamera.app.model.PhotoItem in project StickerCamera by Skykai521.

the class GalleryAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final GalleryHolder holder;
    int width = DistanceUtil.getCameraAlbumWidth();
    if (convertView == null) {
        LayoutInflater layoutInflater = LayoutInflater.from(mContext);
        convertView = layoutInflater.inflate(R.layout.item_gallery, null);
        holder = new GalleryHolder();
        holder.sample = (ImageView) convertView.findViewById(R.id.gallery_sample_image);
        holder.sample.setLayoutParams(new AbsListView.LayoutParams(width, width));
        convertView.setTag(holder);
    } else {
        holder = (GalleryHolder) convertView.getTag();
    }
    final PhotoItem gallery = (PhotoItem) getItem(position);
    ImageLoaderUtils.displayLocalImage(gallery.getImageUri(), holder.sample, null);
    return convertView;
}
Also used : PhotoItem(com.stickercamera.app.model.PhotoItem) LayoutInflater(android.view.LayoutInflater) AbsListView(android.widget.AbsListView)

Aggregations

PhotoItem (com.stickercamera.app.model.PhotoItem)6 ArrayList (java.util.ArrayList)2 Cursor (android.database.Cursor)1 LayoutInflater (android.view.LayoutInflater)1 SurfaceHolder (android.view.SurfaceHolder)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)1 GridView (android.widget.GridView)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 Album (com.stickercamera.app.model.Album)1 File (java.io.File)1 FileFilter (java.io.FileFilter)1 HashMap (java.util.HashMap)1