diff --git a/PhotoPicker-release.aar b/PhotoPicker-release.aar index 57cd95f..1ec6cfc 100644 Binary files a/PhotoPicker-release.aar and b/PhotoPicker-release.aar differ diff --git a/PhotoPicker/src/main/java/me/iwf/photopicker/widget/MultiPickResultView.java b/PhotoPicker/src/main/java/me/iwf/photopicker/widget/MultiPickResultView.java index 59bcbc6..79c510f 100644 --- a/PhotoPicker/src/main/java/me/iwf/photopicker/widget/MultiPickResultView.java +++ b/PhotoPicker/src/main/java/me/iwf/photopicker/widget/MultiPickResultView.java @@ -15,6 +15,7 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; +import java.util.List; import me.iwf.photopicker.PhotoPickUtils; @@ -93,11 +94,25 @@ public void init(Activity context,@MultiPicAction int action, ArrayList photoAdapter = new PhotoAdapter(context, selectedPhotos); photoAdapter.setAction(action); recyclerView.setAdapter(photoAdapter); + //recyclerView.setLayoutFrozen(true); } + public void showPics(List paths){ + if (paths != null){ + selectedPhotos.clear(); + selectedPhotos.addAll(paths); + photoAdapter.notifyDataSetChanged(); + } + + } + + + + + diff --git a/PhotoPicker/src/main/java/me/iwf/photopicker/widget/PhotoAdapter.java b/PhotoPicker/src/main/java/me/iwf/photopicker/widget/PhotoAdapter.java index 4fd85d9..dbff3c6 100644 --- a/PhotoPicker/src/main/java/me/iwf/photopicker/widget/PhotoAdapter.java +++ b/PhotoPicker/src/main/java/me/iwf/photopicker/widget/PhotoAdapter.java @@ -30,6 +30,7 @@ public class PhotoAdapter extends RecyclerView.Adapter photoPaths) { this.photoPaths = photoPaths; this.mContext = mContext; inflater = LayoutInflater.from(mContext); + padding = dip2Px(8); } @@ -68,18 +70,30 @@ public void refresh(ArrayList photoPaths){ return new PhotoViewHolder(itemView); } + public int dip2Px(int dip) { + // px/dip = density; + float density = mContext.getResources().getDisplayMetrics().density; + int px = (int) (dip * density + .5f); + return px; + } + int padding; @Override public void onBindViewHolder(final PhotoViewHolder holder, final int position) { if (action == MultiPickResultView.ACTION_SELECT){ + // RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) holder.ivPhoto.getLayoutParams(); + + holder.ivPhoto.setPadding(padding,padding,padding,padding); + + if (position == getItemCount() -1){//最后一个始终是+号,点击能够跳去添加图片 Glide.with(mContext) .load("") .centerCrop() .thumbnail(0.1f) - .placeholder(R.drawable.icon_propser_add) - .error(R.drawable.icon_propser_add) + .placeholder(R.drawable.icon_pic_default) + .error(R.drawable.icon_pic_default) .into(holder.ivPhoto); holder.ivPhoto.setOnClickListener(new View.OnClickListener() { @Override @@ -89,12 +103,14 @@ public void onClick(View v) { }else { PhotoPickUtils.startPick((Activity) mContext,photoPaths); } - } }); + holder.deleteBtn.setVisibility(View.GONE); + }else { - //String str = photoPaths.get(position); + String str = photoPaths.get(position); + Log.e("file",str); Uri uri = Uri.fromFile(new File(photoPaths.get(position))); Glide.with(mContext) .load(uri) @@ -104,10 +120,19 @@ public void onClick(View v) { .error(R.drawable.__picker_ic_broken_image_black_48dp) .into(holder.ivPhoto); - holder.ivPhoto.setOnClickListener(new View.OnClickListener() { + + holder.deleteBtn.setVisibility(View.VISIBLE); + holder.deleteBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + photoPaths.remove(position); + notifyDataSetChanged(); + } + }); + holder.ivPhoto.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { PhotoPreview.builder() .setPhotos(photoPaths) .setAction(action) @@ -121,7 +146,9 @@ public void onClick(View v) { //Uri uri = Uri.parse(photoPaths.get(position)); Log.e("pic",photoPaths.get(position)); Glide.with(mContext) - .load("http://i.imgur.com/idojSYm.png") + .load(photoPaths.get(position)) + .centerCrop() + .thumbnail(0.1f) .placeholder(R.drawable.__picker_default_weixin) .error(R.drawable.__picker_ic_broken_image_black_48dp) .into(holder.ivPhoto); @@ -145,6 +172,8 @@ public void onClick(View v) { } + + @Override public int getItemCount() { return action == MultiPickResultView.ACTION_SELECT ? photoPaths.size()+1 : photoPaths.size(); } @@ -154,6 +183,7 @@ public static class PhotoViewHolder extends RecyclerView.ViewHolder { private ImageView ivPhoto; private View vSelected; public View cover; + public View deleteBtn; public PhotoViewHolder(View itemView) { super(itemView); ivPhoto = (ImageView) itemView.findViewById(R.id.iv_photo); @@ -161,6 +191,8 @@ public PhotoViewHolder(View itemView) { vSelected.setVisibility(View.GONE); cover = itemView.findViewById(R.id.cover); cover.setVisibility(View.GONE); + deleteBtn = itemView.findViewById(R.id.v_delete); + deleteBtn.setVisibility(View.GONE); } } diff --git a/PhotoPicker/src/main/res/drawable-xxhdpi/icon_delete.png b/PhotoPicker/src/main/res/drawable-xxhdpi/icon_delete.png new file mode 100644 index 0000000..5abce6d Binary files /dev/null and b/PhotoPicker/src/main/res/drawable-xxhdpi/icon_delete.png differ diff --git a/PhotoPicker/src/main/res/drawable-xxhdpi/icon_pic_default.png b/PhotoPicker/src/main/res/drawable-xxhdpi/icon_pic_default.png new file mode 100644 index 0000000..15813b5 Binary files /dev/null and b/PhotoPicker/src/main/res/drawable-xxhdpi/icon_pic_default.png differ diff --git a/PhotoPicker/src/main/res/layout/__picker_item_photo.xml b/PhotoPicker/src/main/res/layout/__picker_item_photo.xml index a45fb56..249c708 100644 --- a/PhotoPicker/src/main/res/layout/__picker_item_photo.xml +++ b/PhotoPicker/src/main/res/layout/__picker_item_photo.xml @@ -20,6 +20,14 @@ android:layout_width="match_parent" android:layout_height="match_parent"/> + + +``` + +选择图片并显示图片: + +``` +recyclerView = (MultiPickResultView) findViewById(R.id.recycler_view); +recyclerView.init(this,MultiPickResultView.ACTION_SELECT,null); + +//onActivityResult里一行代码回调 + recyclerView.onActivityResult(requestCode,resultCode,data); +``` + + + +只显示图片 + +``` +//可以初始化时传入地址 +recyclerViewShowOnly.init(this,MultiPickResultView.ACTION_ONLY_SHOW,pathslook); + +//也可以后续设置地址: + recyclerViewShowOnly.showPics(pathslook); +``` ### Pick Photo + ```java PhotoPickUtils.startPick(this); ``` + + + + ### ### onActivityResult diff --git a/demo.apk b/demo.apk index fe6455d..f1b557f 100644 Binary files a/demo.apk and b/demo.apk differ diff --git a/multview.png b/multview.png new file mode 100644 index 0000000..34248b1 Binary files /dev/null and b/multview.png differ diff --git a/photopickerdemo/src/main/java/me/iwf/PhotoPickerDemo/MainActivity.java b/photopickerdemo/src/main/java/me/iwf/PhotoPickerDemo/MainActivity.java index 2e38934..d790909 100644 --- a/photopickerdemo/src/main/java/me/iwf/PhotoPickerDemo/MainActivity.java +++ b/photopickerdemo/src/main/java/me/iwf/PhotoPickerDemo/MainActivity.java @@ -32,17 +32,26 @@ enum RequestCode { } } MultiPickResultView recyclerView; + + MultiPickResultView recyclerViewShowOnly; /* PhotoAdapter photoAdapter; ArrayList selectedPhotos = new ArrayList<>();*/ //public final static int REQUEST_CODE = 1; + ArrayList pathslook ; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + pathslook = new ArrayList<>(); recyclerView = (MultiPickResultView) findViewById(R.id.recycler_view); + recyclerView.init(this,MultiPickResultView.ACTION_SELECT,null); + + recyclerViewShowOnly = (MultiPickResultView) findViewById(R.id.recycler_onlylook); + recyclerViewShowOnly.init(this,MultiPickResultView.ACTION_ONLY_SHOW,pathslook); ArrayList photos = new ArrayList<>(); photos.add("https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2545179197,2573899739&fm=21&gp=0.jpg"); photos.add("https://timgsa.baidu.com/timg?image&quality=80&size=b10000_10000&sec=1471325032244&di=71570ed352a1b823584c3b3b1b5bd57f&imgtype=jpg&src=http%3A%2F%2Ffile27.mafengwo.net%2FM00%2FB2%2F12%2FwKgB6lO0ahWAMhL8AAV1yBFJDJw20.jpeg"); @@ -50,7 +59,7 @@ enum RequestCode { photos.add("https://timgsa.baidu.com/timg?image&quality=80&size=b10000_10000&sec=1471325032243&di=d40f796d46782144ba0adf798253f080&imgtype=jpg&src=http%3A%2F%2Fimglf0.ph.126.net%2F1EnYPI5Vzo2fCkyy2GsJKg%3D%3D%2F2829667940890114965.jpg"); photos.add("https://timgsa.baidu.com/timg?image&quality=80&size=b10000_10000&sec=1471325032243&di=bbb10b09ddb5338b53432af1c3789c39&imgtype=jpg&src=http%3A%2F%2Ffile25.mafengwo.net%2FM00%2F0A%2FAA%2FwKgB4lMC256AYLqGAAGklurKzyM52.rbook_comment.w1024.jpeg"); - recyclerView.init(this,MultiPickResultView.ACTION_SELECT,null); + /* photoAdapter = new PhotoAdapter(this, selectedPhotos); recyclerView.setLayoutManager(new StaggeredGridLayoutManager(4, OrientationHelper.VERTICAL)); @@ -111,6 +120,10 @@ public void onClick(View v) { recyclerView.onActivityResult(requestCode,resultCode,data); + + + recyclerViewShowOnly.showPics(recyclerView.getPhotos()); + /* PhotoPickUtils.onActivityResult(requestCode, resultCode, data, new PhotoPickUtils.PickHandler() { @Override public void onPickSuccess(ArrayList photos) { diff --git a/photopickerdemo/src/main/res/layout/activity_main.xml b/photopickerdemo/src/main/res/layout/activity_main.xml index 66c49cd..a703cac 100644 --- a/photopickerdemo/src/main/res/layout/activity_main.xml +++ b/photopickerdemo/src/main/res/layout/activity_main.xml @@ -1,70 +1,94 @@ - -