use of me.iwf.photopicker.entity.Photo in project PhotoPicker by donglua.
the class PhotoPickerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
boolean showCamera = getIntent().getBooleanExtra(EXTRA_SHOW_CAMERA, true);
boolean showGif = getIntent().getBooleanExtra(EXTRA_SHOW_GIF, false);
boolean previewEnabled = getIntent().getBooleanExtra(EXTRA_PREVIEW_ENABLED, true);
setShowGif(showGif);
setContentView(R.layout.__picker_activity_photo_picker);
Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
setTitle(R.string.__picker_title);
ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
actionBar.setElevation(25);
}
maxCount = getIntent().getIntExtra(EXTRA_MAX_COUNT, DEFAULT_MAX_COUNT);
int columnNumber = getIntent().getIntExtra(EXTRA_GRID_COLUMN, DEFAULT_COLUMN_NUMBER);
originalPhotos = getIntent().getStringArrayListExtra(EXTRA_ORIGINAL_PHOTOS);
pickerFragment = (PhotoPickerFragment) getSupportFragmentManager().findFragmentByTag("tag");
if (pickerFragment == null) {
pickerFragment = PhotoPickerFragment.newInstance(showCamera, showGif, previewEnabled, columnNumber, maxCount, originalPhotos);
getSupportFragmentManager().beginTransaction().replace(R.id.container, pickerFragment, "tag").commit();
getSupportFragmentManager().executePendingTransactions();
}
pickerFragment.getPhotoGridAdapter().setOnItemCheckListener(new OnItemCheckListener() {
@Override
public boolean onItemCheck(int position, Photo photo, final int selectedItemCount) {
menuDoneItem.setEnabled(selectedItemCount > 0);
if (maxCount <= 1) {
List<String> photos = pickerFragment.getPhotoGridAdapter().getSelectedPhotos();
if (!photos.contains(photo.getPath())) {
photos.clear();
pickerFragment.getPhotoGridAdapter().notifyDataSetChanged();
}
return true;
}
if (selectedItemCount > maxCount) {
Toast.makeText(getActivity(), getString(R.string.__picker_over_max_count_tips, maxCount), LENGTH_LONG).show();
return false;
}
if (maxCount > 1) {
menuDoneItem.setTitle(getString(R.string.__picker_done_with_count, selectedItemCount, maxCount));
} else {
menuDoneItem.setTitle(getString(R.string.__picker_done));
}
return true;
}
});
}
use of me.iwf.photopicker.entity.Photo in project PhotoPicker by donglua.
the class PhotoGridAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final PhotoViewHolder holder, int position) {
if (getItemViewType(position) == ITEM_TYPE_PHOTO) {
List<Photo> photos = getCurrentPhotos();
final Photo photo;
if (showCamera()) {
photo = photos.get(position - 1);
} else {
photo = photos.get(position);
}
boolean canLoadImage = AndroidLifecycleUtils.canLoadImage(holder.ivPhoto.getContext());
if (canLoadImage) {
final RequestOptions options = new RequestOptions();
options.centerCrop().dontAnimate().override(imageSize, imageSize).placeholder(R.drawable.__picker_ic_photo_black_48dp).error(R.drawable.__picker_ic_broken_image_black_48dp);
glide.setDefaultRequestOptions(options).load(new File(photo.getPath())).thumbnail(0.5f).into(holder.ivPhoto);
}
final boolean isChecked = isSelected(photo);
holder.vSelected.setSelected(isChecked);
holder.ivPhoto.setSelected(isChecked);
holder.ivPhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (onPhotoClickListener != null) {
int pos = holder.getAdapterPosition();
if (previewEnable) {
onPhotoClickListener.onClick(view, pos, showCamera());
} else {
holder.vSelected.performClick();
}
}
}
});
holder.vSelected.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int pos = holder.getAdapterPosition();
boolean isEnable = true;
if (onItemCheckListener != null) {
isEnable = onItemCheckListener.onItemCheck(pos, photo, getSelectedPhotos().size() + (isSelected(photo) ? -1 : 1));
}
if (isEnable) {
toggleSelection(photo);
notifyItemChanged(pos);
}
}
});
} else {
holder.ivPhoto.setImageResource(R.drawable.__picker_camera);
}
}
use of me.iwf.photopicker.entity.Photo in project PhotoPicker by donglua.
the class PhotoPickerFragment method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == ImageCaptureManager.REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
if (captureManager == null) {
FragmentActivity activity = getActivity();
captureManager = new ImageCaptureManager(activity);
}
captureManager.galleryAddPic();
if (directories.size() > 0) {
String path = captureManager.getCurrentPhotoPath();
PhotoDirectory directory = directories.get(INDEX_ALL_PHOTOS);
directory.getPhotos().add(INDEX_ALL_PHOTOS, new Photo(path.hashCode(), path));
directory.setCoverPath(path);
photoGridAdapter.notifyDataSetChanged();
}
}
}
Aggregations