Search in sources :

Example 26 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 27 with ListPopupWindow

use of android.support.v7.widget.ListPopupWindow in project MultiImageSelector by lovetuzitong.

the class MultiImageSelectorFragment method createPopupFolderList.

/**
 * Create popup ListView
 */
private void createPopupFolderList() {
    Point point = ScreenUtils.getScreenSize(getActivity());
    int width = point.x;
    int height = (int) (point.y * (4.5f / 8.0f));
    mFolderPopupWindow = new ListPopupWindow(getActivity());
    mFolderPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    mFolderPopupWindow.setAdapter(mFolderAdapter);
    mFolderPopupWindow.setContentWidth(width);
    mFolderPopupWindow.setWidth(width);
    mFolderPopupWindow.setHeight(height);
    mFolderPopupWindow.setAnchorView(mPopupAnchorView);
    mFolderPopupWindow.setModal(true);
    mFolderPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            mFolderAdapter.setSelectIndex(i);
            final int index = i;
            final AdapterView v = adapterView;
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    mFolderPopupWindow.dismiss();
                    if (index == 0) {
                        getActivity().getSupportLoaderManager().restartLoader(LOADER_ALL, null, mLoaderCallback);
                        mCategoryText.setText(R.string.mis_folder_all);
                        if (showCamera()) {
                            mImageAdapter.setShowCamera(true);
                        } else {
                            mImageAdapter.setShowCamera(false);
                        }
                    } else {
                        Folder folder = (Folder) v.getAdapter().getItem(index);
                        if (null != folder) {
                            mImageAdapter.setData(folder.images);
                            mCategoryText.setText(folder.name);
                            if (resultList != null && resultList.size() > 0) {
                                mImageAdapter.setDefaultSelected(resultList);
                            }
                        }
                        mImageAdapter.setShowCamera(false);
                    }
                    mGridView.smoothScrollToPosition(0);
                }
            }, 100);
        }
    });
}
Also used : Handler(android.os.Handler) Point(android.graphics.Point) Folder(me.nereo.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) Point(android.graphics.Point) ListPopupWindow(android.support.v7.widget.ListPopupWindow) ColorDrawable(android.graphics.drawable.ColorDrawable) AdapterView(android.widget.AdapterView)

Example 28 with ListPopupWindow

use of android.support.v7.widget.ListPopupWindow 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 29 with ListPopupWindow

use of android.support.v7.widget.ListPopupWindow in project SeaStar by 13120241790.

the class MultiImageSelectorFragment method createPopupFolderList.

/**
 * 创建弹出的ListView
 */
private void createPopupFolderList(int width, int height) {
    mFolderPopupWindow = new ListPopupWindow(getActivity());
    mFolderPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    mFolderPopupWindow.setAdapter(mFolderAdapter);
    mFolderPopupWindow.setContentWidth(width);
    mFolderPopupWindow.setWidth(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) {
            mFolderAdapter.setSelectIndex(i);
            final int index = i;
            final AdapterView v = adapterView;
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    mFolderPopupWindow.dismiss();
                    if (index == 0) {
                        getActivity().getSupportLoaderManager().restartLoader(LOADER_ALL, null, mLoaderCallback);
                        mCategoryText.setText(R.string.folder_all);
                        if (mIsShowCamera) {
                            mImageAdapter.setShowCamera(true);
                        } else {
                            mImageAdapter.setShowCamera(false);
                        }
                    } else {
                        Folder folder = (Folder) v.getAdapter().getItem(index);
                        if (null != folder) {
                            mImageAdapter.setData(folder.images);
                            mCategoryText.setText(folder.name);
                            // 设定默认选择
                            if (resultList != null && resultList.size() > 0) {
                                mImageAdapter.setDefaultSelected(resultList);
                            }
                        }
                        mImageAdapter.setShowCamera(false);
                    }
                    // 滑动到最初始位置
                    mGridView.smoothScrollToPosition(0);
                }
            }, 100);
        }
    });
}
Also used : ListPopupWindow(android.support.v7.widget.ListPopupWindow) ColorDrawable(android.graphics.drawable.ColorDrawable) Handler(android.os.Handler) AdapterView(android.widget.AdapterView) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView)

Aggregations

ListPopupWindow (android.support.v7.widget.ListPopupWindow)28 View (android.view.View)25 AdapterView (android.widget.AdapterView)25 TextView (android.widget.TextView)19 ImageView (android.widget.ImageView)10 ArrayAdapter (android.widget.ArrayAdapter)8 ArrayList (java.util.ArrayList)8 RecyclerView (android.support.v7.widget.RecyclerView)7 Handler (android.os.Handler)5 AbsListView (android.widget.AbsListView)5 List (java.util.List)5 DialogInterface (android.content.DialogInterface)4 ColorDrawable (android.graphics.drawable.ColorDrawable)4 Button (android.widget.Button)4 ListView (android.widget.ListView)4 SuppressLint (android.annotation.SuppressLint)3 Point (android.graphics.Point)3 Bundle (android.os.Bundle)3 AlertDialog (android.support.v7.app.AlertDialog)3 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)3