类android.support.v7.widget.ListPopupWindow源码实例Demo

下面列出了怎么用android.support.v7.widget.ListPopupWindow的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: FilePicker   文件: ToolbarSpinner.java
public ToolbarSpinner(@NonNull Context context) {
    mListPopupWindow = new ListPopupWindow(context, null, R.attr.listPopupWindowStyle);
    mListPopupWindow.setModal(true);
    float density = context.getResources().getDisplayMetrics().density;
    mListPopupWindow.setContentWidth((int) (216 * density));
    mListPopupWindow.setHorizontalOffset((int) (16 * density));
    mListPopupWindow.setVerticalOffset((int) (-48 * density));

    mListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ToolbarSpinner.this.onItemSelected(parent.getContext(), position);
            if (mOnItemSelectedListener != null) {
                mOnItemSelectedListener.onItemSelected(parent, view, position, id);
            }
        }
    });
}
 
源代码2 项目: AndroidDownload   文件: ToolbarSpinner.java
public ToolbarSpinner(@NonNull Context context) {
    mListPopupWindow = new ListPopupWindow(context, null, R.attr.listPopupWindowStyle);
    mListPopupWindow.setModal(true);
    float density = context.getResources().getDisplayMetrics().density;
    mListPopupWindow.setContentWidth((int) (216 * density));
    mListPopupWindow.setHorizontalOffset((int) (16 * density));
    mListPopupWindow.setVerticalOffset((int) (-48 * density));

    mListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ToolbarSpinner.this.onItemSelected(parent.getContext(), position);
            if (mOnItemSelectedListener != null) {
                mOnItemSelectedListener.onItemSelected(parent, view, position, id);
            }
        }
    });
}
 
源代码3 项目: AlbumCameraRecorder   文件: AlbumsSpinner.java
public AlbumsSpinner(@NonNull Context context) {
    // 实例化ListPopupWindow控件
    mListPopupWindow = new ListPopupWindow(context, null, R.attr.listPopupWindowStyle);
    mListPopupWindow.setModal(true);
    float density = context.getResources().getDisplayMetrics().density;
    mListPopupWindow.setContentWidth((int) (216 * density));
    mListPopupWindow.setHorizontalOffset((int) (16 * density));
    mListPopupWindow.setVerticalOffset((int) (-48 * density));

    // 点击事件
    mListPopupWindow.setOnItemClickListener((parent, view, position, id) -> {
        AlbumsSpinner.this.onItemSelected(parent.getContext(), position);
        if (mOnItemSelectedListener != null) {
            mOnItemSelectedListener.onItemSelected(parent, view, position, id);
        }
    });
}
 
源代码4 项目: fangzhuishushenqi   文件: SelectionLayout.java
private void createPopupWindow() {
    mListPopupWindow = new ListPopupWindow(mContext);
    mAdapter = new SelAdapter(mContext, data);
    mListPopupWindow.setAdapter(mAdapter);
    mListPopupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
    mListPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    mListPopupWindow.setAnchorView(parent.getChildAt(0));
    mListPopupWindow.setForceIgnoreOutsideTouch(false);
    mListPopupWindow.setOnItemClickListener(this);
    mListPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            ivArrow.startAnimation(operatingAnim2);
            isOpen = false;
        }
    });
    mListPopupWindow.setModal(true);
}
 
源代码5 项目: fangzhuishushenqi   文件: ReadEPubActivity.java
private void initTocList() {
    mTocListAdapter = new TocListAdapter(this, mChapterList, "", 1);
    mTocListAdapter.setEpub(true);
    mTocListPopupWindow = new ListPopupWindow(this);
    mTocListPopupWindow.setAdapter(mTocListAdapter);
    mTocListPopupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
    mTocListPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    mTocListPopupWindow.setAnchorView(mCommonToolbar);
    mTocListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mTocListPopupWindow.dismiss();
            currentChapter = position + 1;
            mTocListAdapter.setCurrentChapter(currentChapter);
            viewpager.setCurrentItem(position);
        }
    });
    mTocListPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            toolbarAnimateHide();
        }
    });
}
 
源代码6 项目: fangzhuishushenqi   文件: SearchActivity.java
private void initAutoList() {
    mAutoAdapter = new AutoCompleteAdapter(this, mAutoList);
    mListPopupWindow = new ListPopupWindow(this);
    mListPopupWindow.setAdapter(mAutoAdapter);
    mListPopupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
    mListPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    mListPopupWindow.setAnchorView(mCommonToolbar);
    mListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mListPopupWindow.dismiss();
            TextView tv = (TextView) view.findViewById(R.id.tvAutoCompleteItem);
            String str = tv.getText().toString();
            search(str);
        }
    });
}
 
源代码7 项目: Matisse   文件: AlbumsSpinner.java
public AlbumsSpinner(@NonNull Context context) {
    mListPopupWindow = new ListPopupWindow(context, null, R.attr.listPopupWindowStyle);
    mListPopupWindow.setModal(true);
    float density = context.getResources().getDisplayMetrics().density;
    mListPopupWindow.setContentWidth((int) (216 * density));
    mListPopupWindow.setHorizontalOffset((int) (16 * density));
    mListPopupWindow.setVerticalOffset((int) (-48 * density));

    mListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            AlbumsSpinner.this.onItemSelected(parent.getContext(), position);
            if (mOnItemSelectedListener != null) {
                mOnItemSelectedListener.onItemSelected(parent, view, position, id);
            }
        }
    });
}
 
源代码8 项目: wallpaperboard   文件: Tooltip.java
private Tooltip(Builder builder) {
    mBuilder = builder;

    mPopupWindow = new ListPopupWindow(mBuilder.mContext);
    mPopupWindow.setContentWidth(getMeasuredWidth(builder.mContext));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Drawable drawable = mPopupWindow.getBackground();
        if (drawable != null) {
            drawable.setColorFilter(ColorHelper.getAttributeColor(
                    builder.mContext, R.attr.card_background), PorterDuff.Mode.SRC_IN);
        }
    } else {
        mPopupWindow.setBackgroundDrawable(new ColorDrawable(
                ColorHelper.getAttributeColor(builder.mContext, R.attr.card_background)));
    }

    mPopupWindow.setListSelector(new ColorDrawable(Color.TRANSPARENT));
    mPopupWindow.setAnchorView(mBuilder.mTo);
    mPopupWindow.setForceIgnoreOutsideTouch(true);
    mPopupWindow.setAdapter(new TooltipAdapter(mBuilder.mContext, this));
}
 
源代码9 项目: QuickNote   文件: PopupWindowFactory.java
public static ListPopupWindow createListPopUpWindow(Context context, View anchor, int[] icons,
                                                    String[] texts, final ListPopUpWindowItemClickListener listener) {
    final ListPopupWindow listPopupWindow = new ListPopupWindow(context);
    PopUpMenuAdapter adapter = new PopUpMenuAdapter(context, icons, texts);
    listPopupWindow.setAdapter(adapter);
    listPopupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
    listPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    listPopupWindow.setAnchorView(anchor);
    listPopupWindow.setModal(true);
    listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                                int position, long id) {
            listener.onItemClick(parent, view, position, id);
            listPopupWindow.dismiss();
        }
    });
    return listPopupWindow;
}
 
源代码10 项目: BookReader   文件: SelectionLayout.java
private void createPopupWindow() {
    mListPopupWindow = new ListPopupWindow(mContext);
    mAdapter = new SelAdapter(mContext, data);
    mListPopupWindow.setAdapter(mAdapter);
    mListPopupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
    mListPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    mListPopupWindow.setAnchorView(parent.getChildAt(0));
    mListPopupWindow.setForceIgnoreOutsideTouch(false);
    mListPopupWindow.setOnItemClickListener(this);
    mListPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            ivArrow.startAnimation(operatingAnim2);
            isOpen = false;
        }
    });
    mListPopupWindow.setModal(true);
}
 
源代码11 项目: BookReader   文件: ReadEPubActivity.java
private void initTocList() {
    mTocListAdapter = new TocListAdapter(this, mChapterList, "", 1);
    mTocListAdapter.setEpub(true);
    mTocListPopupWindow = new ListPopupWindow(this);
    mTocListPopupWindow.setAdapter(mTocListAdapter);
    mTocListPopupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
    mTocListPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    mTocListPopupWindow.setAnchorView(mCommonToolbar);
    mTocListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mTocListPopupWindow.dismiss();
            currentChapter = position + 1;
            mTocListAdapter.setCurrentChapter(currentChapter);
            viewpager.setCurrentItem(position);
        }
    });
    mTocListPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            toolbarAnimateHide();
        }
    });
}
 
源代码12 项目: BookReader   文件: SearchActivity.java
private void initAutoList() {
    mAutoAdapter = new AutoCompleteAdapter(this, mAutoList);
    mListPopupWindow = new ListPopupWindow(this);
    mListPopupWindow.setAdapter(mAutoAdapter);
    mListPopupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
    mListPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    mListPopupWindow.setAnchorView(mCommonToolbar);
    mListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mListPopupWindow.dismiss();
            TextView tv = (TextView) view.findViewById(R.id.tvAutoCompleteItem);
            String str = tv.getText().toString();
            search(str);
        }
    });
}
 
源代码13 项目: ImageSelector   文件: MultiImageSelectorFragment.java
void showDirectories() {
	if (imageDirectories.size() <= 1) {
		return;
	}
	final ListPopupWindow popupWindow = new ListPopupWindow(this.getActivity());
	popupWindow.setBackgroundDrawable(new ColorDrawable(-1));
	popupWindow.setAdapter(new DirectoryAdapter(this.getActivity(), this.imageDirectories));
	popupWindow.setWidth(-1);
	int itemHeight = this.getActivity().getResources().getDimensionPixelOffset(R.dimen.size_60);
	popupWindow.setHeight(this.imageDirectories.size() >= 5 ? itemHeight * 5 : itemHeight * this.imageDirectories.size() + getActivity().getResources().getDimensionPixelOffset(R.dimen.size_10));
	popupWindow.setAnchorView(this.btnBack);
	popupWindow.setModal(true);
	popupWindow.setOnItemClickListener(new OnItemClickListener() {
		public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
			txtTitle.setText(imageDirectories.get(position).getName());
			mAdapter.changeData(imageDirectories.get(position).getImages());
			currentDirectory = position;
			popupWindow.dismiss();
		}
	});
	popupWindow.show();
	popupWindow.getListView().setDividerHeight(getActivity().getResources().getDimensionPixelOffset(R.dimen.size_10));
	popupWindow.getListView().setDivider(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
	popupWindow.setSelection(this.currentDirectory);
}
 
源代码14 项目: youqu_master   文件: ImgSelFragment.java
private void createPopupFolderList(int width, int height) {
    folderPopupWindow = new ListPopupWindow(getActivity());
    folderPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    folderPopupWindow.setAdapter(folderListAdapter);
    folderPopupWindow.setContentWidth(width);
    folderPopupWindow.setWidth(width);
    folderPopupWindow.setHeight(height);
    folderPopupWindow.setAnchorView(rlBottom);
    folderPopupWindow.setModal(true);
    folderListAdapter.setOnFloderChangeListener(new OnFolderChangeListener() {
        @Override
        public void onChange(int position, Folder folder) {
            folderPopupWindow.dismiss();
            if (position == 0) {
                getActivity().getSupportLoaderManager().restartLoader(LOADER_ALL, null, mLoaderCallback);
                btnAlbumSelected.setText("所有图片");
            } else {
                imageList.clear();
                if (config.needCamera)
                    imageList.add(new Image());
                imageList.addAll(folder.images);
                imageListAdapter.notifyDataSetChanged();

                btnAlbumSelected.setText(folder.name);
            }
        }
    });
}
 
源代码15 项目: fangzhuishushenqi   文件: ReadActivity.java
private void initTocList() {
    mTocListAdapter = new TocListAdapter(this, mChapterList, bookId, currentChapter);
    mTocListPopupWindow = new ListPopupWindow(this);
    mTocListPopupWindow.setAdapter(mTocListAdapter);
    mTocListPopupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
    mTocListPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    mTocListPopupWindow.setAnchorView(mLlBookReadTop);
    mTocListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mTocListPopupWindow.dismiss();
            currentChapter = position + 1;
            mTocListAdapter.setCurrentChapter(currentChapter);
            startRead = false;
            showDialog();
            readCurrentChapter();
            hideReadBar();
        }
    });
    mTocListPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            gone(mTvBookReadTocTitle);
            visible(mTvBookReadReading, mTvBookReadCommunity, mTvBookReadChangeSource);
        }
    });
}
 
源代码16 项目: wallpaperboard   文件: Popup.java
private Popup(Builder builder) {
    mPopupWindow = new ListPopupWindow(builder.mContext);
    mAdapter = new PopupAdapter(builder.mContext, builder.mItems);


    int width = getMeasuredWidth(builder.mContext);
    mPopupWindow.setContentWidth(width);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Drawable drawable = mPopupWindow.getBackground();
        if (drawable != null) {
            drawable.setColorFilter(ColorHelper.getAttributeColor(
                    builder.mContext, R.attr.card_background), PorterDuff.Mode.SRC_IN);
        }
    } else {
        mPopupWindow.setBackgroundDrawable(new ColorDrawable(
                ColorHelper.getAttributeColor(builder.mContext, R.attr.card_background)));
    }

    mPopupWindow.setAnchorView(builder.mTo);
    mPopupWindow.setAdapter(mAdapter);
    mPopupWindow.setOnItemClickListener((adapterView, view, i, l) -> {
        if (builder.mCallback != null) {
            builder.mCallback.onClick(this, i);
            return;
        }

        mPopupWindow.dismiss();
    });
}
 
源代码17 项目: xmpp   文件: MultiImageSelectorFragment.java
/**
 * 创建弹出的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(R.string.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);
        }
    });
}
 
源代码18 项目: candybar-library   文件: Popup.java
private Popup(Builder builder) {
    mPopupWindow = new ListPopupWindow(builder.mContext);
    mAdapter = new PopupAdapter(builder.mContext, builder.mItems);

    int width = getMeasuredWidth(builder.mContext);
    mPopupWindow.setWidth(width);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Drawable drawable = mPopupWindow.getBackground();
        if (drawable != null) {
            drawable.setColorFilter(ColorHelper.getAttributeColor(
                    builder.mContext, R.attr.card_background), PorterDuff.Mode.SRC_IN);
        }
    } else {
        mPopupWindow.setBackgroundDrawable(new ColorDrawable(
                ColorHelper.getAttributeColor(builder.mContext, R.attr.card_background)));
    }

    mPopupWindow.setAnchorView(builder.mTo);
    mPopupWindow.setAdapter(mAdapter);
    mPopupWindow.setOnItemClickListener((adapterView, view, i, l) -> {
        if (builder.mCallback != null) {
            builder.mCallback.onClick(this, i);
            return;
        }

        mPopupWindow.dismiss();
    });
}
 
源代码19 项目: ImageSelector   文件: ImgSelFragment.java
private void createPopupFolderList(int width, int height) {
    folderPopupWindow = new ListPopupWindow(getActivity());
    folderPopupWindow.setAnimationStyle(R.style.PopupAnimBottom);
    folderPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    folderPopupWindow.setAdapter(folderListAdapter);
    folderPopupWindow.setContentWidth(width);
    folderPopupWindow.setWidth(width);
    folderPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    folderPopupWindow.setAnchorView(rlBottom);
    folderPopupWindow.setModal(true);
    folderListAdapter.setOnFloderChangeListener(new OnFolderChangeListener() {
        @Override
        public void onChange(int position, Folder folder) {
            folderPopupWindow.dismiss();
            if (position == 0) {
                getActivity().getSupportLoaderManager().restartLoader(LOADER_ALL, null, mLoaderCallback);
                btnAlbumSelected.setText(config.allImagesText);
            } else {
                imageList.clear();
                if (config.needCamera)
                    imageList.add(new Image());
                imageList.addAll(folder.images);
                imageListAdapter.notifyDataSetChanged();

                btnAlbumSelected.setText(folder.name);
            }
        }
    });
    folderPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            setBackgroundAlpha(1.0f);
        }
    });
}
 
源代码20 项目: BookReader   文件: ReadActivity.java
private void initTocList() {
    mTocListAdapter = new TocListAdapter(this, mChapterList, bookId, currentChapter);
    mTocListPopupWindow = new ListPopupWindow(this);
    mTocListPopupWindow.setAdapter(mTocListAdapter);
    mTocListPopupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
    mTocListPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    mTocListPopupWindow.setAnchorView(mLlBookReadTop);
    mTocListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mTocListPopupWindow.dismiss();
            currentChapter = position + 1;
            mTocListAdapter.setCurrentChapter(currentChapter);
            startRead = false;
            showDialog();
            readCurrentChapter();
            hideReadBar();
        }
    });
    mTocListPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            gone(mTvBookReadTocTitle);
            visible(mTvBookReadReading, mTvBookReadCommunity, mTvBookReadChangeSource);
        }
    });
}
 
源代码21 项目: mosby   文件: LabelLayout.java
private void init() {

    View.inflate(getContext(), R.layout.view_label_layout, this);

    LayoutTransition transition = new LayoutTransition();
    transition.enableTransitionType(LayoutTransition.CHANGING);
    this.setLayoutTransition(transition);

    adapter = new LabelAdapter(getContext());
    popUpWindow = new ListPopupWindow(getContext());
    popUpWindow.setAnchorView(this);
    popUpWindow.setAdapter(adapter);
    popUpWindow.setWidth(DimensUtils.dpToPx(getContext(), 140));
    popUpWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
      @Override public void onDismiss() {
        showLabel();
      }
    });
    popUpWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
      @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Label label = (Label) adapter.getItem(position);
        if (!label.getName().equals(mail.getLabel())) {
          presenter.setLabel(mail, label.getName());
          popUpWindow.dismiss();
        }
      }
    });

    setOnClickListener(new OnClickListener() {
      @Override public void onClick(View v) {
        loadData(false);
      }
    });
  }
 
源代码22 项目: Silence   文件: TransportOptionsPopup.java
public TransportOptionsPopup(@NonNull Context context, @NonNull View anchor, @NonNull SelectedListener listener) {
  super(context);
  this.listener = listener;
  this.adapter  = new TransportOptionsAdapter(context, new LinkedList<TransportOption>());

  setVerticalOffset(context.getResources().getDimensionPixelOffset(R.dimen.transport_selection_popup_yoff));
  setHorizontalOffset(context.getResources().getDimensionPixelOffset(R.dimen.transport_selection_popup_xoff));
  setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
  setModal(true);
  setAnchorView(anchor);
  setAdapter(adapter);
  setContentWidth(context.getResources().getDimensionPixelSize(R.dimen.transport_selection_popup_width));

  setOnItemClickListener(this);
}
 
源代码23 项目: floatingsearchview   文件: MenuPopupHelper.java
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;
        mTreeObserver = anchor.getViewTreeObserver(); // Refresh to latest
        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;
}
 
源代码24 项目: Falcon   文件: SampleActivity.java
@OnClick(R.id.show_popup)
public void showPopup() {
  ListPopupWindow listPopupWindow = new ListPopupWindow(this, null);

  String[] data = {"Item 1", "Item 2", "Item 3"};
  ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, data);
  listPopupWindow.setAdapter(adapter);

  listPopupWindow.setAnchorView(findViewById(R.id.show_popup));
  listPopupWindow.show();
}
 
/**
 * 创建弹出的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);
        }
    });
}
 
/**
 * 创建弹出的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.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);

        }
    });
}
 
源代码27 项目: PicturePicker   文件: PictureGridActivity.java
/**
 * 初始化展示文件夹列表的popupWindow
 */
private ListPopupWindow initFolderListPopupWindow() {

    listPopupWindow = new ListPopupWindow(this);
    listPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
    //ListPopupWindow总会相对于这个View 锚点
    listPopupWindow.setAnchorView(llFootBar);
    listPopupWindow.setDropDownGravity(Gravity.BOTTOM);
    //是否为模态,影响返回键的处理
    listPopupWindow.setModal(true);
    listPopupWindow.setContentWidth(ListPopupWindow.MATCH_PARENT);
    listPopupWindow.setWidth(ListPopupWindow.MATCH_PARENT);

    folderListAdapter = new PopupFolderListAdapter(this, pictureFolderList);
    listPopupWindow.setAdapter(folderListAdapter);

    listPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            Utils.setActivityBackgroundAlpha(PictureGridActivity.this, 1.0f);
        }
    });

    listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            PictureFolder pictureFolder = pictureFolderList.get(position);
            if (!TextUtils.equals(pictureFolder.folderAbsPath, folderListAdapter.getCurrentSelectFolderPath())) {
                folderListAdapter.notifyDataSetChanged(pictureFolder.folderAbsPath);
                //更新底部文件夹名称
                setBtnImgFolderText(pictureFolder.folderName);
                //更新显示的图片
                notifyPictureGrid(pictureFolder.pictureItemList);
            }

            listPopupWindow.dismiss();
        }
    });

    return listPopupWindow;
}
 
源代码28 项目: ImageChoose   文件: MultiImageSelectorFragment.java
/**
 * 创建弹出的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);
                            if(mIsShowText && mode==MODE_MULTI){//多选的时候才显示文本
                                mImageAdapter.setShowTxt(true);
                            }else{
                                mImageAdapter.setShowTxt(false);
                            }
                        }else {
                            mImageAdapter.setShowCamera(false);
                            mImageAdapter.setShowTxt(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);
                        mImageAdapter.setShowTxt(false);
                    }

                    // 滑动到最初始位置
                    mGridView.smoothScrollToPosition(0);
                }
            }, 100);

        }
    });
}
 
/**
 * 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);

        }
    });
}
 
源代码30 项目: HeartBeat   文件: MultiImageSelectorFragment.java
/**
 * 创建弹出的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.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);

        }
    });
}
 
 同包方法