Search in sources :

Example 6 with ListPopupWindow

use of android.support.v7.widget.ListPopupWindow in project MultiPhotoPicker by wangeason.

the class PhotoPickerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    showCamera = getIntent().getBooleanExtra(EXTRA_SHOW_CAMERA, true);
    boolean showGif = getIntent().getBooleanExtra(EXTRA_SHOW_GIF, false);
    multiChoose = getIntent().getBooleanExtra(EXTRA_MULTI_CHOOSE, false);
    setShowGif(showGif);
    setContentView(R.layout.activity_photo_picker);
    captureManager = new ImageCaptureManager(getActivity());
    Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setTitle(R.string.images);
    setSupportActionBar(mToolbar);
    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);
    minCount = getIntent().getIntExtra(EXTRA_MIN_COUNT, DEFAULT_MIN_COUNT);
    btnDoneItem = (Button) findViewById(R.id.done);
    btnDoneItem.setText(getString(R.string.done_with_count, 0, maxCount));
    btnDoneItem.setEnabled(false);
    btnDoneItem.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            ArrayList<String> selectedPhotos = pickerFragment.getPhotoGridAdapter().getSelectedPhotoPaths();
            if (selectedPhotos.size() >= minCount) {
                intent.putStringArrayListExtra(KEY_SELECTED_PHOTOS, selectedPhotos);
                setResult(RESULT_OK, intent);
                finish();
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(PhotoPickerActivity.this);
                builder.setTitle(R.string.choose_more).setCancelable(true).setMessage(getString(R.string.min_count_tips, minCount)).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).create().show();
            }
        }
    });
    final Button btSwitchDirectory = (Button) findViewById(R.id.button);
    pickerFragment = (PhotoPickerFragment) getSupportFragmentManager().findFragmentById(R.id.photoPickerFragment);
    final ListPopupWindow listPopupWindow = new ListPopupWindow(getActivity());
    listPopupWindow.setWidth(ListPopupWindow.MATCH_PARENT);
    listPopupWindow.setAnchorView(findViewById(R.id.ll_control));
    listPopupWindow.setAdapter(pickerFragment.getListAdapter());
    listPopupWindow.setModal(true);
    listPopupWindow.setDropDownGravity(Gravity.BOTTOM);
    listPopupWindow.setAnimationStyle(R.style.Animation_AppCompat_DropDownUp);
    listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            listPopupWindow.dismiss();
            PhotoDirectory directory = pickerFragment.getDirectories().get(position);
            btSwitchDirectory.setText(directory.getName());
            pickerFragment.getPhotoGridAdapter().setCurrentDirectoryIndex(position);
            pickerFragment.getPhotoGridAdapter().notifyDataSetChanged();
        }
    });
    btSwitchDirectory.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (listPopupWindow.isShowing()) {
                listPopupWindow.dismiss();
            } else if (!getActivity().isFinishing()) {
                listPopupWindow.setHeight(Math.round(pickerFragment.getView().getHeight() * 0.8f));
                listPopupWindow.show();
            }
        }
    });
    multiGridAdapter = pickerFragment.getPhotoGridAdapter();
    multiGridAdapter.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(int position, Photo photo, int selectedItemCount, int selectTimes) {
            if (multiChoose) {
                if (photo.getSelectedTimes() > 0) {
                    if (selectedItemCount >= maxCount) {
                        multiGridAdapter.del(photo);
                        multiGridAdapter.notifyItemChanged(position);
                    } else {
                        multiGridAdapter.add(photo);
                        multiGridAdapter.notifyItemChanged(position);
                    }
                } else {
                    if (selectedItemCount >= maxCount) {
                        Toast.makeText(getActivity(), getString(R.string.over_max_count_tips, maxCount), LENGTH_LONG).show();
                    } else {
                        multiGridAdapter.add(photo);
                        multiGridAdapter.notifyItemChanged(position);
                    }
                }
            } else {
                if (maxCount <= 1) {
                    if (photo.getSelectedTimes() > 0) {
                        multiGridAdapter.del(0);
                        multiGridAdapter.notifyItemChanged(position);
                    } else {
                        multiGridAdapter.clearSelection();
                        multiGridAdapter.add(photo);
                        multiGridAdapter.notifyDataSetChanged();
                    }
                } else {
                    if (photo.getSelectedTimes() > 0) {
                        multiGridAdapter.del(photo);
                        multiGridAdapter.notifyItemChanged(position);
                    } else {
                        if (selectedItemCount >= maxCount) {
                            Toast.makeText(getActivity(), getString(R.string.over_max_count_tips, maxCount), LENGTH_LONG).show();
                        } else {
                            multiGridAdapter.add(photo);
                            multiGridAdapter.notifyItemChanged(position);
                        }
                    }
                }
            }
            selectedPhotoAdapter.notifyDataSetChanged();
            refreshDoneBtn();
        }
    });
    selectedPhotoAdapter = new PhotoSelectedAdapter(getActivity(), multiGridAdapter.getSelectedPhotos());
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.selected_photos);
    LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(selectedPhotoAdapter);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    selectedPhotoAdapter.setOnSelectedItemClickListener(new OnSelectedItemClickListener() {

        @Override
        public void onClick(View v, int position) {
            if (selectedPagerFragment != null && selectedPagerFragment.isVisible()) {
                selectedPagerFragment.getViewPager().setCurrentItem(position);
            } else {
                List<String> photos = multiGridAdapter.getSelectedPhotoPaths();
                int[] screenLocation = new int[2];
                v.getLocationOnScreen(screenLocation);
                ImagePagerFragment imagePagerFragment = ImagePagerFragment.newInstance(photos, position, screenLocation, v.getWidth(), v.getHeight());
                addImagePagerFragment(imagePagerFragment, true);
            }
        }
    });
    selectedPhotoAdapter.setOnSelectedItemDelListener(new OnSelectedItemDelListener() {

        @Override
        public void onClick(int position, MultiSelectedPhoto path) {
            multiGridAdapter.getSelectedPhotos().get(position).getPhoto().del();
            multiGridAdapter.getSelectedPhotos().remove(position);
            multiGridAdapter.notifyDataSetChanged();
            selectedPhotoAdapter.notifyDataSetChanged();
            refreshDoneBtn();
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) ImagePagerFragment(io.github.wangeason.multiphotopicker.fragment.ImagePagerFragment) Photo(io.github.wangeason.multiphotopicker.entity.Photo) MultiSelectedPhoto(io.github.wangeason.multiphotopicker.entity.MultiSelectedPhoto) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) ListPopupWindow(android.support.v7.widget.ListPopupWindow) Button(android.widget.Button) PhotoSelectedAdapter(io.github.wangeason.multiphotopicker.adapter.PhotoSelectedAdapter) OnSelectedItemClickListener(io.github.wangeason.multiphotopicker.event.OnSelectedItemClickListener) ArrayList(java.util.ArrayList) List(java.util.List) ImageCaptureManager(io.github.wangeason.multiphotopicker.utils.ImageCaptureManager) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar) PhotoDirectory(io.github.wangeason.multiphotopicker.entity.PhotoDirectory) OnItemClickListener(io.github.wangeason.multiphotopicker.event.OnItemClickListener) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) OnSelectedItemDelListener(io.github.wangeason.multiphotopicker.event.OnSelectedItemDelListener) MultiSelectedPhoto(io.github.wangeason.multiphotopicker.entity.MultiSelectedPhoto) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView)

Example 7 with ListPopupWindow

use of android.support.v7.widget.ListPopupWindow in project WordPress-Android by wordpress-mobile.

the class PostsListAdapter method showPagePopupMenu.

/*
     * user tapped "..." next to a page, show a popup menu of choices
     */
private void showPagePopupMenu(View view, final PostModel page) {
    Context context = view.getContext();
    final ListPopupWindow listPopup = new ListPopupWindow(context);
    listPopup.setAnchorView(view);
    listPopup.setWidth(context.getResources().getDimensionPixelSize(R.dimen.menu_item_width));
    listPopup.setModal(true);
    listPopup.setAdapter(new PageMenuAdapter(context, page));
    listPopup.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            listPopup.dismiss();
            if (mOnPostButtonClickListener != null) {
                int buttonId = (int) id;
                mOnPostButtonClickListener.onPostButtonClicked(buttonId, page);
            }
        }
    });
    listPopup.show();
}
Also used : Context(android.content.Context) ListPopupWindow(android.support.v7.widget.ListPopupWindow) AdapterView(android.widget.AdapterView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) WPNetworkImageView(org.wordpress.android.widgets.WPNetworkImageView) RecyclerView(android.support.v7.widget.RecyclerView)

Example 8 with ListPopupWindow

use of android.support.v7.widget.ListPopupWindow in project floatingsearchview by arimorty.

the class MenuPopupHelper method tryShow.

public boolean tryShow() {
    mPopup = new ListPopupWindow(mContext, null, mPopupStyleAttr, mPopupStyleRes);
    mPopup.setOnDismissListener(this);
    mPopup.setOnItemClickListener(this);
    mPopup.setAdapter(mAdapter);
    mPopup.setModal(true);
    View anchor = mAnchorView;
    if (anchor != null) {
        final boolean addGlobalListener = mTreeObserver == null;
        // Refresh to latest
        mTreeObserver = anchor.getViewTreeObserver();
        if (addGlobalListener)
            mTreeObserver.addOnGlobalLayoutListener(this);
        mPopup.setAnchorView(anchor);
        mPopup.setDropDownGravity(mDropDownGravity);
    } else {
        return false;
    }
    if (!mHasContentWidth) {
        mContentWidth = measureContentWidth();
        mHasContentWidth = true;
    }
    mPopup.setContentWidth(mContentWidth);
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
    int vertOffset = -mAnchorView.getHeight() + Util.dpToPx(4);
    int horizontalOffset = -mContentWidth + mAnchorView.getWidth();
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        vertOffset = -mAnchorView.getHeight() - Util.dpToPx(4);
        horizontalOffset = -mContentWidth + mAnchorView.getWidth() - Util.dpToPx(8);
    }
    mPopup.setVerticalOffset(vertOffset);
    mPopup.setHorizontalOffset(horizontalOffset);
    mPopup.show();
    mPopup.getListView().setOnKeyListener(this);
    return true;
}
Also used : ListPopupWindow(android.support.v7.widget.ListPopupWindow) MenuView(android.support.v7.view.menu.MenuView) ListMenuItemView(android.support.v7.view.menu.ListMenuItemView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 9 with ListPopupWindow

use of android.support.v7.widget.ListPopupWindow in project UltimateAndroid by cymcsg.

the class MultiImageSelectorFragment method createPopupFolderList.

/**
     * 创建弹出的ListView
     */
private void createPopupFolderList(int width, int height) {
    mFolderPopupWindow = new ListPopupWindow(getActivity());
    mFolderPopupWindow.setAdapter(mFolderAdapter);
    mFolderPopupWindow.setContentWidth(width);
    mFolderPopupWindow.setHeight(height * 5 / 8);
    mFolderPopupWindow.setAnchorView(mPopupAnchorView);
    mFolderPopupWindow.setModal(true);
    mFolderPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (i == 0) {
                getActivity().getSupportLoaderManager().restartLoader(LOADER_ALL, null, mLoaderCallback);
                mCategoryText.setText("folder_all");
                mImageAdapter.setShowCamera(true);
            } else {
                Folder folder = (Folder) adapterView.getAdapter().getItem(i);
                if (null != folder) {
                    Bundle args = new Bundle();
                    args.putString("path", folder.path);
                    getActivity().getSupportLoaderManager().restartLoader(LOADER_CATEGORY, args, mLoaderCallback);
                    mCategoryText.setText(folder.name);
                }
                mImageAdapter.setShowCamera(false);
            }
            mFolderAdapter.setSelectIndex(i);
            mFolderPopupWindow.dismiss();
            // 滑动到最初始位置
            mGridView.smoothScrollToPosition(0);
        }
    });
}
Also used : ListPopupWindow(android.support.v7.widget.ListPopupWindow) Bundle(android.os.Bundle) AdapterView(android.widget.AdapterView) Folder(com.marshalchen.common.uimodule.multi_image_selector.bean.Folder) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView)

Example 10 with ListPopupWindow

use of android.support.v7.widget.ListPopupWindow 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;
}
Also used : PhotoDirectory(me.iwf.photopicker.entity.PhotoDirectory) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) PopupDirectoryListAdapter(me.iwf.photopicker.adapter.PopupDirectoryListAdapter) 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(me.iwf.photopicker.event.OnPhotoClickListener)

Aggregations

View (android.view.View)15 AdapterView (android.widget.AdapterView)15 ListPopupWindow (android.support.v7.widget.ListPopupWindow)14 TextView (android.widget.TextView)11 RecyclerView (android.support.v7.widget.RecyclerView)5 GridView (android.widget.GridView)4 ImageView (android.widget.ImageView)4 AbsListView (android.widget.AbsListView)3 PopupWindow (android.widget.PopupWindow)3 ArrayList (java.util.ArrayList)3 Context (android.content.Context)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 Handler (android.os.Handler)2 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)2 SearchView (android.support.v7.widget.SearchView)2 Button (android.widget.Button)2 ListView (android.widget.ListView)2 BindView (butterknife.BindView)2 TocListAdapter (com.justwayward.reader.ui.adapter.TocListAdapter)2 List (java.util.List)2