Skip to content

Commit

Permalink
multiview
Browse files Browse the repository at this point in the history
  • Loading branch information
hss01248 committed Sep 1, 2016
1 parent 4dd474b commit a48cea8
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 69 deletions.
Binary file modified PhotoPicker-release.aar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -93,11 +94,25 @@ public void init(Activity context,@MultiPicAction int action, ArrayList<String>
photoAdapter = new PhotoAdapter(context, selectedPhotos);
photoAdapter.setAction(action);
recyclerView.setAdapter(photoAdapter);
//recyclerView.setLayoutFrozen(true);


}


public void showPics(List<String> paths){
if (paths != null){
selectedPhotos.clear();
selectedPhotos.addAll(paths);
photoAdapter.notifyDataSetChanged();
}

}








Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class PhotoAdapter extends RecyclerView.Adapter<PhotoAdapter.PhotoViewHol

private Context mContext;


public void setAction(@MultiPickResultView.MultiPicAction int action) {
this.action = action;
}
Expand All @@ -43,6 +44,7 @@ public PhotoAdapter(Context mContext, ArrayList<String> photoPaths) {
this.photoPaths = photoPaths;
this.mContext = mContext;
inflater = LayoutInflater.from(mContext);
padding = dip2Px(8);

}

Expand All @@ -68,18 +70,30 @@ public void refresh(ArrayList<String> 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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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);
Expand All @@ -145,6 +172,8 @@ public void onClick(View v) {
}




@Override public int getItemCount() {
return action == MultiPickResultView.ACTION_SELECT ? photoPaths.size()+1 : photoPaths.size();
}
Expand All @@ -154,13 +183,16 @@ 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);
vSelected = itemView.findViewById(R.id.v_selected);
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);
}
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions PhotoPicker/src/main/res/layout/__picker_item_photo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<View
android:visibility="gone"
android:id="@+id/v_delete"
android:background="@drawable/icon_delete"
android:layout_alignParentRight="true"
android:layout_width="15dp"
android:layout_height="15dp"/>

<ImageView
android:layout_margin="5dip"
android:layout_alignParentTop="true"
Expand Down
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ demo apk:见项目根目录下demo.apk



封装好的图片显示组件:(上方是图片选择,下面是只显示图片的组件)

![multview](multview.png)



---

# Usage
Expand All @@ -67,21 +73,60 @@ Add it in your root build.gradle at the end of repositories:
Step 2. Add the dependency

dependencies {
compile 'com.github.glassLake:PhotoPicker:1.0.0'
compile 'com.github.glassLake:PhotoPicker:1.0.1'
}



## 完全使用封装好的组件



xml:

```
<me.iwf.photopicker.widget.MultiPickResultView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/recycler_view"/>
```

选择图片并显示图片:

```
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
Expand Down
Binary file modified demo.apk
Binary file not shown.
Binary file added multview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,34 @@ enum RequestCode {
}
}
MultiPickResultView recyclerView;

MultiPickResultView recyclerViewShowOnly;
/* PhotoAdapter photoAdapter;
ArrayList<String> selectedPhotos = new ArrayList<>();*/

//public final static int REQUEST_CODE = 1;

ArrayList<String> 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<String> 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");
photos.add("https://timgsa.baidu.com/timg?image&quality=80&size=b10000_10000&sec=1471325032243&di=67dfaed98491c3a94965571ed4343951&imgtype=jpg&src=http%3A%2F%2Fwww.5068.com%2Fu%2Ffaceimg%2F20140725173411.jpg");
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));
Expand Down Expand Up @@ -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<String> photos) {
Expand Down
Loading

0 comments on commit a48cea8

Please sign in to comment.