android.widget.ListPopupWindow#setAnchorView ( )源码实例Demo

下面列出了android.widget.ListPopupWindow#setAnchorView ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: talk-android   文件: RecipientEditTextView.java
private void showAddress(final DrawableRecipientChip currentChip, final ListPopupWindow popup,
                         int width) {
    if (!mAttachedToWindow) {
        return;
    }
    int line = getLayout().getLineForOffset(getChipStart(currentChip));
    int bottom = calculateOffsetFromBottom(line);
    // Align the alternates popup with the left side of the View,
    // regardless of the position of the chip tapped.
    popup.setWidth(width);
    popup.setAnchorView(this);
    popup.setVerticalOffset(bottom);
    popup.setAdapter(createSingleAddressAdapter(currentChip));
    popup.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            unselectChip(currentChip);
            popup.dismiss();
        }
    });
    popup.show();
    ListView listView = popup.getListView();
    listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    listView.setItemChecked(0, true);
}
 
源代码2 项目: ChipsLibrary   文件: RecipientEditTextView.java
private void showAddress(final DrawableRecipientChip currentChip,final ListPopupWindow popup,final int width)
{
if(!mAttachedToWindow)
  return;
final int line=getLayout().getLineForOffset(getChipStart(currentChip));
final int bottom=calculateOffsetFromBottom(line);
// Align the alternates popup with the left side of the View,
// regardless of the position of the chip tapped.
popup.setWidth(width);
popup.setAnchorView(this);
popup.setVerticalOffset(bottom);
popup.setAdapter(createSingleAddressAdapter(currentChip));
popup.setOnItemClickListener(new OnItemClickListener()
  {
    @Override
    public void onItemClick(final AdapterView<?> parent,final View view,final int position,final long id)
      {
      unselectChip(currentChip);
      popup.dismiss();
      }
  });
popup.show();
final ListView listView=popup.getListView();
listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
listView.setItemChecked(0,true);
}
 
源代码3 项目: cwac-security   文件: MainActivity.java
protected void showListPopupWindow() {
  ArrayAdapter<String> adapter=
    new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,
      ITEMS);
  final ListPopupWindow popup=new ListPopupWindow(this);

  popup.setAnchorView(popupAnchor);
  popup.setAdapter(adapter);
  popup.setOnItemClickListener(
    new AdapterView.OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView<?> parent, View view,
                              int position, long id) {
        popup.dismiss();
      }
    });
  popup.show();
}
 
源代码4 项目: lua-for-android   文件: AutoCompletePanel.java
private void initAutoCompletePanel() {
    _autoCompletePanel = new ListPopupWindow(_context);
    _autoCompletePanel.setAnchorView(_textField);
    _adapter = new MyAdapter(_context, android.R.layout.simple_list_item_1);
    _autoCompletePanel.setAdapter(_adapter);
    //_autoCompletePanel.setDropDownGravity(Gravity.BOTTOM | Gravity.LEFT);
    _filter = _adapter.getFilter();
    setHeight(300);

    TypedArray array = _context.getTheme().obtainStyledAttributes(new int[]{
            android.R.attr.colorBackground,
            android.R.attr.textColorPrimary,
    });
    int backgroundColor = array.getColor(0, 0xFF00FF);
    int textColor = array.getColor(1, 0xFF00FF);
    array.recycle();
    gd = new GradientDrawable();
    gd.setColor(backgroundColor);
    gd.setCornerRadius(4);
    gd.setStroke(1, textColor);
    setTextColor(textColor);
    _autoCompletePanel.setBackgroundDrawable(gd);
    _autoCompletePanel.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> p1, View p2, int p3, long p4) {
            // TODO: Implement this method
            _textField.replaceText(_textField.getCaretPosition() - _constraint.length(), _constraint.length(), ((TextView) p2).getText().toString());
            _adapter.abort();
            dismiss();
        }
    });

}
 
源代码5 项目: NovelReader   文件: SelectorView.java
private void createPopWindow(){
    popupWindow = new ListPopupWindow(getContext());
    popupAdapter = new SelectorAdapter();
    popupWindow.setAnchorView(parent.getChildAt(0));
    popupWindow.setAdapter(popupAdapter);
    popupWindow.setWidth(WindowManager.LayoutParams.MATCH_PARENT);
    popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
    //获取焦点
    popupWindow.setModal(true);

    popupWindow.setOnItemClickListener(this);
    popupWindow.setOnDismissListener(this);
}
 
源代码6 项目: BreadcrumbsView   文件: BreadcrumbsAdapter.java
private void createPopupWindow() {
	popupWindow = new ListPopupWindow(getPopupThemedContext());
	popupWindow.setAnchorView(imageButton);
	popupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
		@Override
		public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
			if (callback != null) {
				callback.onItemChange(parent, getAdapterPosition() / 2, getItems().get(getAdapterPosition() / 2 + 1).getItems().get(i));
				popupWindow.dismiss();
			}
		}
	});
	imageButton.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
		@Override
		public void onGlobalLayout() {
			popupWindow.setVerticalOffset(-imageButton.getMeasuredHeight() + DROPDOWN_OFFSET_Y_FIX);
			imageButton.getViewTreeObserver().removeOnGlobalLayoutListener(this);
		}
	});
}
 
源代码7 项目: EditSpinner   文件: EditSpinner.java
private void initPopupWindow() {
    popupWindow = new ListPopupWindow(mContext) {

        @Override
        public void show() {
            super.show();
            mRightImageTopView.setClickable(true);
            mRightIv.startAnimation(mAnimation);
        }

        @Override
        public void dismiss() {
            super.dismiss();
        }

    };
    popupWindow.setOnItemClickListener(this);
    popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    popupWindow.setPromptPosition(ListPopupWindow.POSITION_PROMPT_BELOW);
    popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setAnchorView(editText);
    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            popupWindowHideTime = System.currentTimeMillis();
            mRightIv.startAnimation(mResetAnimation);
        }
    });
}
 
源代码8 项目: TLint   文件: GalleryActivity.java
private void createPopupFolderList() {
    mFolderPopupWindow = new ListPopupWindow(this);
    mFolderPopupWindow.setAdapter(mFolderAdapter);
    mFolderPopupWindow.setContentWidth(ListPopupWindow.MATCH_PARENT);
    mFolderPopupWindow.setWidth(ListPopupWindow.MATCH_PARENT);
    mFolderPopupWindow.setHeight(ListPopupWindow.MATCH_PARENT);
    mFolderPopupWindow.setAnchorView(toolbar);
    mFolderPopupWindow.setModal(true);
    mFolderPopupWindow.setAnimationStyle(R.style.popwindow_anim_style);
    mFolderPopupWindow.setOnItemClickListener(this);
}
 
源代码9 项目: holoaccent   文件: ButtonFragment.java
@Override public boolean onLongClick(View v) {
	String[] versions = { "Camera", "Laptop", "Watch", "Smartphone",
			"Television" };
	final ListPopupWindow listPopupWindow = new ListPopupWindow(
			getActivity());
	listPopupWindow.setAdapter(new ArrayAdapter<String>(getActivity(),
			android.R.layout.simple_dropdown_item_1line, versions));
	listPopupWindow.setAnchorView(mListPopupButton);
	listPopupWindow.setWidth(300);
	listPopupWindow.setHeight(400);

	listPopupWindow.setModal(true);
	listPopupWindow.show();
	return false;
}
 
源代码10 项目: home-assistant-Android   文件: SettingsActivity.java
@Override
public boolean onPreferenceTreeClick(Preference preference) {
    View preferenceView = getListView().findViewHolderForAdapterPosition(preference.getOrder()).itemView;

    switch (preference.getKey()) {
        case Common.PREF_LOCATION_UPDATE_INTERVAL:
            ListPopupWindow listPopupWindow = new ListPopupWindow(getActivity());
            listPopupWindow.setAnchorView(preferenceView);
            listPopupWindow.setAdapter(new ArrayAdapter<>(getActivity(), android.support.design.R.layout.support_simple_spinner_dropdown_item, getResources().getStringArray(R.array.location_update_interval_summaries)));
            listPopupWindow.setContentWidth(getResources().getDimensionPixelSize(R.dimen.popup_window_width));
            listPopupWindow.setHorizontalOffset(getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin));
            listPopupWindow.setOnItemClickListener((parent, view, position, id) -> {
                Log.d("Selected", String.valueOf(position));
                prefs.edit().putInt(Common.PREF_LOCATION_UPDATE_INTERVAL,
                        getResources().getIntArray(R.array.location_update_interval_values)[position]).apply();
                listPopupWindow.dismiss();
                updatePreferenceSummaries();
                updateLocationTracker();
            });
            listPopupWindow.show();
            return true;
        case Common.PREF_RESET_HOST_MISMATCHES:
            prefs.edit().remove(Common.PREF_ALLOWED_HOST_MISMATCHES_KEY).apply();
            Toast.makeText(getActivity(), R.string.toast_ignored_ssl_mismatches_cleared, Toast.LENGTH_SHORT).show();
            updatePreferenceSummaries();
            return true;
        case Common.HELP_TRANSLATE:
            CustomTabsSession session = ((SettingsActivity) getActivity()).getCustomTabsSession();
            if (session != null) {
                @SuppressWarnings("deprecation") CustomTabsIntent intent = new CustomTabsIntent.Builder(session)
                        .setShowTitle(true)
                        .enableUrlBarHiding()
                        .setToolbarColor(getResources().getColor(R.color.primary))
                        .build();
                intent.launchUrl(getActivity(), Uri.parse(Common.CROWDIN_URL));
            }
            return true;
        default:
            return super.onPreferenceTreeClick(preference);
    }
}
 
源代码11 项目: SimplicityBrowser   文件: AdapterBookmarks.java
private void showFilterPopup() {
    try {
        final ListPopupWindow popupWindow = new ListPopupWindow(context);
        List<Item> itemList = new ArrayList<>();
        itemList.add(new Item(context.getResources().getString(R.string.delete_bookmark), R.drawable.ic_delete));
        itemList.add(new Item(context.getResources().getString(R.string.rename_bookmark), R.drawable.ic_rename));
        itemList.add(new Item(context.getResources().getString(R.string.share_bookmark), R.drawable.ic_share));
        ListAdapter adapter = new ListPopupWindowAdapter(context, itemList);
        popupWindow.setAnchorView(delete);
        popupWindow.setAdapter(adapter);
        popupWindow.setOnDismissListener(popupWindow::dismiss);
        popupWindow.setOnItemClickListener((adapterView, view, i, l) -> {
            switch (i) {
                case 0:
                    popupWindow.dismiss();
                    deleteAlert();
                    break;
                case 1:
                    popupWindow.dismiss();
                    editAlert();
                    break;
                case 2:
                    popupWindow.dismiss();
                    try {
                        Intent share = new Intent(Intent.ACTION_SEND);
                        share.setType("text/plain");
                        share.putExtra(Intent.EXTRA_TEXT, bookmark.getUrl());
                        context.startActivity(Intent.createChooser(share, bookmark.getTitle()));
                    }catch (ActivityNotFoundException ignored){
                    }catch (Exception p){
                        p.printStackTrace();
                    }
                    break;
                default:
                    popupWindow.dismiss();
                    break;
            }

        });
        popupWindow.show();

    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
private void createPopupFolderList(int width, int height) {
	
    folderPopupWindow = new ListPopupWindow(getActivity());
    folderPopupWindow.setBackgroundDrawable(null);
    folderPopupWindow.setAdapter(folderAdapter);
    folderPopupWindow.setContentWidth(width);
    folderPopupWindow.setWidth(width);
    folderPopupWindow.setHeight(height * 5 / 8);
    folderPopupWindow.setAnchorView(popupAnchorView);
    folderPopupWindow.setModal(true);
    folderPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

            folderAdapter.setSelectIndex(i);

            final int index = i;
            final AdapterView v = adapterView;

            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    folderPopupWindow.dismiss();

                    if (index == 0) {
                        getActivity().getSupportLoaderManager().restartLoader(LOADER_ALL, null, mLoaderCallback);
                        category_button.setText(R.string.all_folder);
                        callback.onChangeAlbum(context.getResources().getString(R.string.all_folder));
                        if (imageConfig.isShowCamera()) {
                            imageAdapter.setShowCamera(true);
                        } else {
                            imageAdapter.setShowCamera(false);
                        }
                    } 
                    else {
                        Folder folder = (Folder) v.getAdapter().getItem(index);
                        if (null != folder) {
                            imageList.clear();
                            imageList.addAll(folder.images);
                            imageAdapter.notifyDataSetChanged();

                            category_button.setText(folder.name);
                            callback.onChangeAlbum(folder.name);
                            if (resultList != null && resultList.size() > 0) {
                                imageAdapter.setDefaultSelected(resultList);
                            }
                        }
                        imageAdapter.setShowCamera(false);
                    }

                    grid_image.smoothScrollToPosition(0);
                }
            }, 100);
        }
    });
    
}