public class MainActivity extendsAppCompatActivity {int REQUEST_CODE = 0;privateNineGridImageView ngiv;private ArrayListphotos;privateDialog dialog;privatecn.com.jwtimes.www.jwtimes.mAdapter mAdapter1;
@Overrideprotected voidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv=findViewById(R.id.tv);
ngiv=findViewById(R.id.ngiv);
tv.setOnClickListener(newView.OnClickListener() {
@Overridepublic voidonClick(View v) {
PhotoPickerIntent intent= new PhotoPickerIntent(MainActivity.this);
intent.setPhotoCount(9);
intent.setShowCamera(true);
startActivityForResult(intent, REQUEST_CODE);
}
});
}
@Overrideprotected void onActivityResult(int requestCode, intresultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);if (resultCode == RESULT_OK && requestCode ==REQUEST_CODE) {if (data != null) {
photos=data.getStringArrayListExtra(PhotoPickerActivity.KEY_SELECTED_PHOTOS);
ngiv.setAdapter(mAdapter);
ngiv.setImagesData(photos);
}
}
}private NineGridImageViewAdapter mAdapter = new NineGridImageViewAdapter() {
@Overrideprotected void onDisplayImage(Context context, ImageView imageView, finalString url) {
Glide.with(context)
.load(url)
.into(imageView);
}
@OverrideprotectedImageView generateImageView(Context context) {return super.generateImageView(context);
}
@Overrideprotected void onItemImageClick(Context context, int index, ListphotoList) {
showBigPicture(context, photos, index);
}
};private void showBigPicture(Context context, final ArrayList photos, final intindex) {
dialog= newDialog(context, R.style.MyDialog);
View contentView= View.inflate(context, R.layout.dialog_tip, null);final ViewPager vp =(ViewPager) contentView.findViewById(R.id.vp);
ImageView ivDelete=(ImageView) contentView.findViewById(R.id.ivDelete);
mAdapter1= new mAdapter(this, photos, dialog);
vp.setAdapter(mAdapter1);
vp.setCurrentItem(index);
ivDelete.setOnClickListener(newView.OnClickListener() {
@Overridepublic voidonClick(View v) {int currentItem =vp.getCurrentItem();
Iterator sListIterator =photos.iterator();while(sListIterator.hasNext()) {
String e=sListIterator.next();if(e.equals(photos.get(currentItem))) {
sListIterator.remove();
mAdapter1.notifyDataSetChanged();break;
}
}
}
});
dialog.setOnDismissListener(newDialogInterface.OnDismissListener() {
@Overridepublic voidonDismiss(DialogInterface dialog) {
ngiv.setAdapter(MainActivity.this.mAdapter);
ngiv.setImagesData(photos);
}
});
dialog.setContentView(contentView);
dialog.setCancelable(true);
dialog.getWindow().setLayout(
getScreenWidth(),
getScreenHeight());
dialog.show();
}public intgetScreenWidth() {
Resources resources=getResources();returnresources.getDisplayMetrics().widthPixels;
}public intgetScreenHeight() {
Resources resources=getResources();returnresources.getDisplayMetrics().heightPixels;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/190791.html原文链接:https://javaforall.cn