Search in sources :

Example 1 with PhotoDirectory

use of com.daotangbill.photopicker.entity.PhotoDirectory in project MLib by DaoBillTang.

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();
        }
    }
}
Also used : PhotoDirectory(com.daotangbill.photopicker.entity.PhotoDirectory) FragmentActivity(android.support.v4.app.FragmentActivity) Photo(com.daotangbill.photopicker.entity.Photo) ImageCaptureManager(com.daotangbill.photopicker.utils.ImageCaptureManager)

Example 2 with PhotoDirectory

use of com.daotangbill.photopicker.entity.PhotoDirectory in project MLib by DaoBillTang.

the class PhotoPickerFragment method onDestroy.

@Override
public void onDestroy() {
    super.onDestroy();
    if (directories == null) {
        return;
    }
    for (PhotoDirectory directory : directories) {
        directory.getPhotoPaths().clear();
        directory.getPhotos().clear();
        directory.setPhotos(null);
    }
    directories.clear();
    directories = null;
}
Also used : PhotoDirectory(com.daotangbill.photopicker.entity.PhotoDirectory)

Example 3 with PhotoDirectory

use of com.daotangbill.photopicker.entity.PhotoDirectory in project MLib by DaoBillTang.

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);
    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();
            ImagePagerFragment imagePagerFragment = ImagePagerFragment.newInstance(photos, index);
            ((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;
}
Also used : PhotoDirectory(com.daotangbill.photopicker.entity.PhotoDirectory) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) ListPopupWindow(android.support.v7.widget.ListPopupWindow) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) RecyclerView(android.support.v7.widget.RecyclerView) AdapterView(android.widget.AdapterView) ArrayList(java.util.ArrayList) List(java.util.List) OnPhotoClickListener(com.daotangbill.photopicker.event.OnPhotoClickListener)

Example 4 with PhotoDirectory

use of com.daotangbill.photopicker.entity.PhotoDirectory in project MLib by DaoBillTang.

the class PhotoPickerFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);
    mGlideRequestManager = Glide.with(this);
    directories = new ArrayList<>();
    originalPhotos = getArguments().getStringArrayList(EXTRA_ORIGIN);
    column = getArguments().getInt(EXTRA_COLUMN, DEFAULT_COLUMN_NUMBER);
    boolean showCamera = getArguments().getBoolean(EXTRA_CAMERA, true);
    boolean previewEnable = getArguments().getBoolean(EXTRA_PREVIEW_ENABLED, true);
    photoGridAdapter = new PhotoGridAdapter(getActivity(), mGlideRequestManager, directories, originalPhotos, column);
    photoGridAdapter.setShowCamera(showCamera);
    photoGridAdapter.setPreviewEnable(previewEnable);
    listAdapter = new PopupDirectoryListAdapter(mGlideRequestManager, directories);
    Bundle mediaStoreArgs = new Bundle();
    boolean showGif = getArguments().getBoolean(EXTRA_GIF);
    mediaStoreArgs.putBoolean(EXTRA_SHOW_GIF, showGif);
    MediaStoreHelper.getPhotoDirs(getActivity(), mediaStoreArgs, new MediaStoreHelper.PhotosResultCallback() {

        @Override
        public void onResultCallback(List<PhotoDirectory> dirs) {
            directories.clear();
            directories.addAll(dirs);
            photoGridAdapter.notifyDataSetChanged();
            listAdapter.notifyDataSetChanged();
            adjustHeight();
        }
    });
    captureManager = new ImageCaptureManager(getActivity());
}
Also used : PhotoDirectory(com.daotangbill.photopicker.entity.PhotoDirectory) PhotoGridAdapter(com.daotangbill.photopicker.adapter.PhotoGridAdapter) Bundle(android.os.Bundle) PopupDirectoryListAdapter(com.daotangbill.photopicker.adapter.PopupDirectoryListAdapter) ImageCaptureManager(com.daotangbill.photopicker.utils.ImageCaptureManager) MediaStoreHelper(com.daotangbill.photopicker.utils.MediaStoreHelper)

Aggregations

PhotoDirectory (com.daotangbill.photopicker.entity.PhotoDirectory)4 ImageCaptureManager (com.daotangbill.photopicker.utils.ImageCaptureManager)2 Bundle (android.os.Bundle)1 FragmentActivity (android.support.v4.app.FragmentActivity)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 ListPopupWindow (android.support.v7.widget.ListPopupWindow)1 RecyclerView (android.support.v7.widget.RecyclerView)1 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 AdapterView (android.widget.AdapterView)1 Button (android.widget.Button)1 PhotoGridAdapter (com.daotangbill.photopicker.adapter.PhotoGridAdapter)1 PopupDirectoryListAdapter (com.daotangbill.photopicker.adapter.PopupDirectoryListAdapter)1 Photo (com.daotangbill.photopicker.entity.Photo)1 OnPhotoClickListener (com.daotangbill.photopicker.event.OnPhotoClickListener)1 MediaStoreHelper (com.daotangbill.photopicker.utils.MediaStoreHelper)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1