Search in sources :

Example 1 with OnItemCheckListener

use of me.iwf.photopicker.event.OnItemCheckListener 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;
        }
    });
}
Also used : Photo(me.iwf.photopicker.entity.Photo) ArrayList(java.util.ArrayList) List(java.util.List) ActionBar(android.support.v7.app.ActionBar) OnItemCheckListener(me.iwf.photopicker.event.OnItemCheckListener) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

ActionBar (android.support.v7.app.ActionBar)1 Toolbar (android.support.v7.widget.Toolbar)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Photo (me.iwf.photopicker.entity.Photo)1 OnItemCheckListener (me.iwf.photopicker.event.OnItemCheckListener)1