use of me.iwf.photopicker.event.OnPhotoClickListener in project PhotoPicker by donglua.
the class PhotoPickerFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.__picker_fragment_photo_picker, container, false);
listAdapter = new PopupDirectoryListAdapter(mGlideRequestManager, directories);
RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.rv_photos);
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(column, OrientationHelper.VERTICAL);
layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_MOVE_ITEMS_BETWEEN_SPANS);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(photoGridAdapter);
recyclerView.setItemAnimator(new DefaultItemAnimator());
final Button btSwitchDirectory = (Button) rootView.findViewById(R.id.button);
listPopupWindow = new ListPopupWindow(getActivity());
listPopupWindow.setWidth(ListPopupWindow.MATCH_PARENT);
listPopupWindow.setAnchorView(btSwitchDirectory);
listPopupWindow.setAdapter(listAdapter);
listPopupWindow.setModal(true);
listPopupWindow.setDropDownGravity(Gravity.BOTTOM);
listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
listPopupWindow.dismiss();
PhotoDirectory directory = directories.get(position);
btSwitchDirectory.setText(directory.getName());
photoGridAdapter.setCurrentDirectoryIndex(position);
photoGridAdapter.notifyDataSetChanged();
}
});
photoGridAdapter.setOnPhotoClickListener(new OnPhotoClickListener() {
@Override
public void onClick(View v, int position, boolean showCamera) {
final int index = showCamera ? position - 1 : position;
List<String> photos = photoGridAdapter.getCurrentPhotoPaths();
int[] screenLocation = new int[2];
v.getLocationOnScreen(screenLocation);
ImagePagerFragment imagePagerFragment = ImagePagerFragment.newInstance(photos, index, screenLocation, v.getWidth(), v.getHeight());
((PhotoPickerActivity) getActivity()).addImagePagerFragment(imagePagerFragment);
}
});
photoGridAdapter.setOnCameraClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (!PermissionsUtils.checkCameraPermission(PhotoPickerFragment.this))
return;
if (!PermissionsUtils.checkWriteStoragePermission(PhotoPickerFragment.this))
return;
openCamera();
}
});
btSwitchDirectory.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (listPopupWindow.isShowing()) {
listPopupWindow.dismiss();
} else if (!getActivity().isFinishing()) {
adjustHeight();
listPopupWindow.show();
}
}
});
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
// Log.d(">>> Picker >>>", "dy = " + dy);
if (Math.abs(dy) > SCROLL_THRESHOLD) {
mGlideRequestManager.pauseRequests();
} else {
resumeRequestsIfNotDestroyed();
}
}
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
resumeRequestsIfNotDestroyed();
}
}
});
return rootView;
}
Aggregations