use of com.lzy.imagepicker.bean.ImageItem in project ImagePicker by jeasonlzy.
the class ImagePickerAdapter method setImages.
public void setImages(List<ImageItem> data) {
mData = new ArrayList<>(data);
if (getItemCount() < maxImgCount) {
mData.add(new ImageItem());
isAdded = true;
} else {
isAdded = false;
}
notifyDataSetChanged();
}
use of com.lzy.imagepicker.bean.ImageItem in project ImagePicker by jeasonlzy.
the class WxDemoActivity method onItemClick.
@Override
public void onItemClick(View view, int position) {
switch(position) {
case IMAGE_ITEM_ADD:
//打开选择,本次允许选择的数量
ImagePicker.getInstance().setSelectLimit(maxImgCount - selImageList.size());
Intent intent = new Intent(this, ImageGridActivity.class);
/**
* 下面两行有需要的可以添加
*/
// intent.putExtra(ImageGridActivity.EXTRAS_TAKE_PICKERS,true); // 是否是直接打开相机
startActivityForResult(intent, REQUEST_CODE_SELECT);
break;
default:
//打开预览
Intent intentPreview = new Intent(this, ImagePreviewDelActivity.class);
intentPreview.putExtra(ImagePicker.EXTRA_IMAGE_ITEMS, (ArrayList<ImageItem>) adapter.getImages());
intentPreview.putExtra(ImagePicker.EXTRA_SELECTED_IMAGE_POSITION, position);
startActivityForResult(intentPreview, REQUEST_CODE_PREVIEW);
break;
}
}
use of com.lzy.imagepicker.bean.ImageItem in project ImagePicker by jeasonlzy.
the class ImageDataSource method onLoadFinished.
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
imageFolders.clear();
if (data != null) {
//所有图片的集合,不分文件夹
ArrayList<ImageItem> allImages = new ArrayList<>();
while (data.moveToNext()) {
//查询数据
String imageName = data.getString(data.getColumnIndexOrThrow(IMAGE_PROJECTION[0]));
String imagePath = data.getString(data.getColumnIndexOrThrow(IMAGE_PROJECTION[1]));
long imageSize = data.getLong(data.getColumnIndexOrThrow(IMAGE_PROJECTION[2]));
int imageWidth = data.getInt(data.getColumnIndexOrThrow(IMAGE_PROJECTION[3]));
int imageHeight = data.getInt(data.getColumnIndexOrThrow(IMAGE_PROJECTION[4]));
String imageMimeType = data.getString(data.getColumnIndexOrThrow(IMAGE_PROJECTION[5]));
long imageAddTime = data.getLong(data.getColumnIndexOrThrow(IMAGE_PROJECTION[6]));
//封装实体
ImageItem imageItem = new ImageItem();
imageItem.name = imageName;
imageItem.path = imagePath;
imageItem.size = imageSize;
imageItem.width = imageWidth;
imageItem.height = imageHeight;
imageItem.mimeType = imageMimeType;
imageItem.addTime = imageAddTime;
allImages.add(imageItem);
//根据父路径分类存放图片
File imageFile = new File(imagePath);
File imageParentFile = imageFile.getParentFile();
ImageFolder imageFolder = new ImageFolder();
imageFolder.name = imageParentFile.getName();
imageFolder.path = imageParentFile.getAbsolutePath();
if (!imageFolders.contains(imageFolder)) {
ArrayList<ImageItem> images = new ArrayList<>();
images.add(imageItem);
imageFolder.cover = imageItem;
imageFolder.images = images;
imageFolders.add(imageFolder);
} else {
imageFolders.get(imageFolders.indexOf(imageFolder)).images.add(imageItem);
}
}
//防止没有图片报异常
if (data.getCount() > 0) {
//构造所有图片的集合
ImageFolder allImagesFolder = new ImageFolder();
allImagesFolder.name = activity.getResources().getString(R.string.all_images);
allImagesFolder.path = "/";
allImagesFolder.cover = allImages.get(0);
allImagesFolder.images = allImages;
//确保第一条是所有图片
imageFolders.add(0, allImagesFolder);
}
}
//回调接口,通知图片数据准备完成
ImagePicker.getInstance().setImageFolders(imageFolders);
loadedListener.onImagesLoaded(imageFolders);
}
use of com.lzy.imagepicker.bean.ImageItem in project ImagePicker by jeasonlzy.
the class ImagePreviewBaseActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_preview);
mCurrentPosition = getIntent().getIntExtra(ImagePicker.EXTRA_SELECTED_IMAGE_POSITION, 0);
// 据说这样会导致大量图片崩溃
mImageItems = (ArrayList<ImageItem>) getIntent().getSerializableExtra(ImagePicker.EXTRA_IMAGE_ITEMS);
// 下面采用弱引用会导致预览崩溃
// mImageItems = (ArrayList<ImageItem>) DataHolder.getInstance().retrieve(DataHolder.DH_CURRENT_IMAGE_FOLDER_ITEMS);
imagePicker = ImagePicker.getInstance();
selectedImages = imagePicker.getSelectedImages();
//初始化控件
content = findViewById(R.id.content);
//因为状态栏透明后,布局整体会上移,所以给头部加上状态栏的margin值,保证头部不会被覆盖
topBar = findViewById(R.id.top_bar);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) topBar.getLayoutParams();
params.topMargin = Utils.getStatusHeight(this);
topBar.setLayoutParams(params);
}
topBar.findViewById(R.id.btn_ok).setVisibility(View.GONE);
topBar.findViewById(R.id.btn_back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
mTitleCount = (TextView) findViewById(R.id.tv_des);
mViewPager = (ViewPagerFixed) findViewById(R.id.viewpager);
mAdapter = new ImagePageAdapter(this, mImageItems);
mAdapter.setPhotoViewClickListener(new ImagePageAdapter.PhotoViewClickListener() {
@Override
public void OnPhotoTapListener(View view, float v, float v1) {
onImageSingleTap();
}
});
mViewPager.setAdapter(mAdapter);
mViewPager.setCurrentItem(mCurrentPosition, false);
//初始化当前页面的状态
mTitleCount.setText(getString(R.string.preview_image_count, mCurrentPosition + 1, mImageItems.size()));
}
use of com.lzy.imagepicker.bean.ImageItem in project WeexErosFramework by bmfe.
the class AbstractWeexActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if (result != null) {
if (result.getContents() == null) {
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
handleDecodeInternally(result.getContents());
}
}
/**
* 读取联系人返回
*/
if (resultCode == RESULT_OK && requestCode == Constant.REQUEST_CODE.REQUEST_CODE_CONTRACT) {
readContractResult(data);
}
/**
* 照片拍摄返回
*/
if (resultCode == RESULT_OK && requestCode == ImagePicker.REQUEST_CODE_TAKE) {
cameraResult();
return;
}
/**
* 选择照片 上传
*/
switch(resultCode) {
case ImagePicker.RESULT_CODE_ITEMS:
if (data != null && requestCode == Constant.ImageConstants.IMAGE_PICKER) {
ArrayList<ImageItem> items = (ArrayList<ImageItem>) data.getSerializableExtra(ImagePicker.EXTRA_RESULT_ITEMS);
UpMultipleImageData(items);
}
break;
}
/**
* 选择照片 返回
*/
switch(resultCode) {
case ImagePicker.RESULT_CODE_ITEMS:
if (data != null && requestCode == Constant.ImageConstants.IMAGE_NOT_UPLOADER_PICKER) {
ArrayList<ImageItem> items = (ArrayList<ImageItem>) data.getSerializableExtra(ImagePicker.EXTRA_RESULT_ITEMS);
pickReturn(items);
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
Aggregations