类android.widget.ListPopupWindow源码实例Demo

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

源代码1 项目: BlockExplorer   文件: TransactionDetailActivity.java
private void init() {

        loading = new AppLoading(this, false, R.string.loading);
        tv_type.setText(Tdp.blockType + "");
        tv_type.setOnClickListener(this);
        btn_search.setOnClickListener(this);
        tv_tag.setVisibility(View.VISIBLE);
        et_hash.setHint("请输入交易Hash");

        mPopup = new ListPopupWindow(this);
        ArrayAdapter adapter = new ArrayAdapter(this, R.layout.layout_block_popup_item, Tdp.blockTypes);
        mPopup.setAdapter(adapter);
        mPopup.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
        mPopup.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
        mPopup.setModal(true);
        mPopup.setOnItemClickListener(this);

        tv_to.setOnClickListener(this);
        tv_from.setOnClickListener(this);
        transactionHash = "";
        if (getIntent() != null && getIntent().hasExtra("transactionHash")) {
            transactionHash = getIntent().getStringExtra("transactionHash");
            searchRequest(transactionHash);
        }
    }
 
源代码2 项目: NaviBee   文件: MainActivity.java
private void setupOverflowMenu() {
    mPopupWindow = new ListPopupWindow(this);
    String[] mPopupWindowItems = new String[]{
            "%ROW_FOR_USER_PROFILE%",
            getResources().getString(R.string.action_settings),
            getResources().getString(R.string.action_log_out)
    };
    mAdapter = new PopupAdapter(mPopupWindowItems, menuClickListeners);

    findViewById(R.id.landing_layout).post(() -> {
        mPopupWindow.setModal(true);
        mPopupWindow.setAnchorView(mOverflowButton);
        mPopupWindow.setAdapter(mAdapter);
        mPopupWindow.setWidth(dpToPx(getResources().getInteger(R.integer.popup_menu_main_width)));
        mPopupWindow.setHeight(ListPopupWindow.WRAP_CONTENT);
        mPopupWindow.setVerticalOffset(-mOverflowButton.getLayoutParams().height);

        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            mPopupWindow.setDropDownGravity(Gravity.START);
        } else {
            mPopupWindow.setDropDownGravity(Gravity.END);
        }
    });
}
 
源代码3 项目: Edit-Spinner   文件: EditSpinner.java
public void showDropDown() {
    if (mPopup.getAnchorView() == null) {
        if (mDropDownAnchorId != View.NO_ID) {
            mPopup.setAnchorView(getRootView().findViewById(mDropDownAnchorId));
        } else {
            mPopup.setAnchorView(this);
        }
    }
    if (!isPopupShowing()) {
        // Make sure the list does not obscure the IME when shown for the first time.
        mPopup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NEEDED);
    }

    requestFocus();
    mPopup.show();
    mPopup.getListView().setOverScrollMode(View.OVER_SCROLL_ALWAYS);

    if (mOnShowListener != null) {
        mOnShowListener.onShow();
    }
}
 
源代码4 项目: 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);
}
 
源代码5 项目: 365browser   文件: DropdownPopupWindow.java
/**
 * Disable hiding on outside tap so that tapping on a text input field associated with the popup
 * will not hide the popup.
 */
public void disableHideOnOutsideTap() {
    // HACK: The ListPopupWindow's mPopup automatically dismisses on an outside tap. There's
    // no way to override it or prevent it, except reaching into ListPopupWindow's hidden
    // API. This allows the C++ controller to completely control showing/hiding the popup.
    // See http://crbug.com/400601
    try {
        Method setForceIgnoreOutsideTouch = ListPopupWindow.class.getMethod(
                "setForceIgnoreOutsideTouch", new Class[] { boolean.class });
        setForceIgnoreOutsideTouch.invoke(this, new Object[] { true });
    } catch (Exception e) {
        Log.e("AutofillPopup",
                "ListPopupWindow.setForceIgnoreOutsideTouch not found",
                e);
    }
}
 
源代码6 项目: 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);
}
 
源代码7 项目: 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();
}
 
源代码8 项目: BlockExplorer   文件: TransactionListActivity.java
private void initView() {
    loading = new AppLoading(this, false, R.string.loading);
    mPopup = new ListPopupWindow(this);
    ArrayAdapter adapter = new ArrayAdapter(this, R.layout.layout_block_popup_item, Tdp.blockTypes);
    mPopup.setAdapter(adapter);
    mPopup.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
    mPopup.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
    mPopup.setModal(true);
    mPopup.setOnItemClickListener(this);

    refreshLayout.setOnRefreshListener(this);
    LinearLayoutManager mLayoutManager = new LinearLayoutManager(recyclerView.getContext());
    mAdapter = new TransactionAdapter(this, Tdp.blockType);
    tv_type = mAdapter.getTypeTextView();
    mAdapter.setOnClickListener(this);
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setAdapter(mAdapter);
    recyclerView.setOnLoadMoreListener(mLayoutManager, mAdapter, new LoadMoreRecycleView.OnLoadMoreListener() {
        @Override
        public void loadMore() {
            if (mAdapter.isHasMore()) {
                loadData();
            }
        }
    });

}
 
源代码9 项目: BlockExplorer   文件: ExplorerActivity.java
private void initView() {
    tv_type.setOnClickListener(this);
    btn_search.setOnClickListener(this);

    mPopup = new ListPopupWindow(this);
    ArrayAdapter adapter = new ArrayAdapter(this, R.layout.layout_block_popup_item, Tdp.blockTypes);
    mPopup.setAdapter(adapter);
    mPopup.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
    mPopup.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
    mPopup.setModal(true);
    mPopup.setOnItemClickListener(this);
}
 
源代码10 项目: 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();
        }
    });

}
 
源代码11 项目: 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);
}
 
源代码12 项目: 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);
		}
	});
}
 
源代码13 项目: Edit-Spinner   文件: EditSpinner.java
protected void performCompletion(View selectedView, int position, long id) {
    if (isPopupShowing()) {
        Object selectedItem;
        if (position < 0) {
            selectedItem = mPopup.getSelectedItem();
        } else {
            selectedItem = mAdapter.getItem(position);
        }
        if (selectedItem == null) {
            if (DEBUG) {
                Log.w(TAG, "performCompletion: no selected item");
            }
            return;
        }

        selectItem(selectedItem);

        if (mItemClickListener != null) {
            final ListPopupWindow list = mPopup;

            if (selectedView == null || position < 0) {
                selectedView = list.getSelectedView();
                position = list.getSelectedItemPosition();
                id = list.getSelectedItemId();
            }
            mItemClickListener.onItemClick(list.getListView(), selectedView, position, id);
        }
    }

    if (mDropDownDismissedOnCompletion) {
        dismissDropDown();
    }
}
 
源代码14 项目: talk-android   文件: TextChipsEditView.java
public TextChipsEditView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setChipDimensions(context, attrs);
        if (sSelectedTextColor == -1) {
            sSelectedTextColor = context.getResources().getColor(android.R.color.white);
        }

        DisplayMetrics metrics = getResources().getDisplayMetrics();
        bitmapSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics);

        setInputType(getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
//        setOnItemClickListener(this);
        setCustomSelectionActionModeCallback(this);
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                if (msg.what == DISMISS) {
                    ((ListPopupWindow) msg.obj).dismiss();
                    return;
                }
                super.handleMessage(msg);
            }
        };
        mTextWatcher = new RecipientTextWatcher();
        addTextChangedListener(mTextWatcher);
        setOnEditorActionListener(this);

        setDropdownChipLayouter(new DropdownChipLayouter(LayoutInflater.from(context), context));
    }
 
源代码15 项目: delion   文件: AppMenu.java
private void setPopupOffset(
        ListPopupWindow popup, int screenRotation, Rect appRect, Rect padding) {
    int[] anchorLocation = new int[2];
    popup.getAnchorView().getLocationInWindow(anchorLocation);
    int anchorHeight = popup.getAnchorView().getHeight();

    // If we have a hardware menu button, locate the app menu closer to the estimated
    // hardware menu button location.
    if (mIsByPermanentButton) {
        int horizontalOffset = -anchorLocation[0];
        switch (screenRotation) {
            case Surface.ROTATION_0:
            case Surface.ROTATION_180:
                horizontalOffset += (appRect.width() - mPopup.getWidth()) / 2;
                break;
            case Surface.ROTATION_90:
                horizontalOffset += appRect.width() - mPopup.getWidth();
                break;
            case Surface.ROTATION_270:
                break;
            default:
                assert false;
                break;
        }
        popup.setHorizontalOffset(horizontalOffset);
        // The menu is displayed above the anchored view, so shift the menu up by the bottom
        // padding of the background.
        popup.setVerticalOffset(-padding.bottom);
    } else {
        // The menu is displayed over and below the anchored view, so shift the menu up by the
        // height of the anchor view.
        popup.setVerticalOffset(-mNegativeSoftwareVerticalOffset - anchorHeight);
    }
}
 
源代码16 项目: delion   文件: AppMenuDragHelper.java
AppMenuDragHelper(Activity activity, AppMenu appMenu, int itemRowHeight) {
    mActivity = activity;
    mAppMenu = appMenu;
    mItemRowHeight = itemRowHeight;
    Resources res = mActivity.getResources();
    mAutoScrollFullVelocity = res.getDimensionPixelSize(R.dimen.auto_scroll_full_velocity);
    // If user is dragging and the popup ListView is too big to display at once,
    // mDragScrolling animator scrolls mPopup.getListView() automatically depending on
    // the user's touch position.
    mDragScrolling.setTimeListener(new TimeAnimator.TimeListener() {
        @Override
        public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
            ListPopupWindow popup = mAppMenu.getPopup();
            if (popup == null || popup.getListView() == null) return;

            // We keep both mDragScrollOffset and mDragScrollOffsetRounded because
            // the actual scrolling is by the rounded value but at the same time we also
            // want to keep the precise scroll value in float.
            mDragScrollOffset += (deltaTime * 0.001f) * mDragScrollingVelocity;
            int diff = Math.round(mDragScrollOffset - mDragScrollOffsetRounded);
            mDragScrollOffsetRounded += diff;
            popup.getListView().smoothScrollBy(diff, 0);

            // Force touch move event to highlight items correctly for the scrolled position.
            if (!Float.isNaN(mLastTouchX) && !Float.isNaN(mLastTouchY)) {
                menuItemAction(Math.round(mLastTouchX), Math.round(mLastTouchY),
                        ITEM_ACTION_HIGHLIGHT);
            }
        }
    });

    // We use medium timeout, the average of tap and long press timeouts. This is consistent
    // with ListPopupWindow#ForwardingListener implementation.
    mTapTimeout =
            (ViewConfiguration.getTapTimeout() + ViewConfiguration.getLongPressTimeout()) / 2;
    mScaledTouchSlop = ViewConfiguration.get(activity).getScaledTouchSlop();
}
 
源代码17 项目: AndroidChromium   文件: AppMenu.java
private void setPopupOffset(
        ListPopupWindow popup, int screenRotation, Rect appRect, Rect padding) {
    int[] anchorLocation = new int[2];
    popup.getAnchorView().getLocationInWindow(anchorLocation);
    int anchorHeight = popup.getAnchorView().getHeight();

    // If we have a hardware menu button, locate the app menu closer to the estimated
    // hardware menu button location.
    if (mIsByPermanentButton) {
        int horizontalOffset = -anchorLocation[0];
        switch (screenRotation) {
            case Surface.ROTATION_0:
            case Surface.ROTATION_180:
                horizontalOffset += (appRect.width() - mPopup.getWidth()) / 2;
                break;
            case Surface.ROTATION_90:
                horizontalOffset += appRect.width() - mPopup.getWidth();
                break;
            case Surface.ROTATION_270:
                break;
            default:
                assert false;
                break;
        }
        popup.setHorizontalOffset(horizontalOffset);
        // The menu is displayed above the anchored view, so shift the menu up by the bottom
        // padding of the background.
        popup.setVerticalOffset(-padding.bottom);
    } else {
        // The menu is displayed over and below the anchored view, so shift the menu up by the
        // height of the anchor view.
        popup.setVerticalOffset(-mNegativeSoftwareVerticalOffset - anchorHeight);
    }
}
 
源代码18 项目: AndroidChromium   文件: AppMenuDragHelper.java
AppMenuDragHelper(Activity activity, AppMenu appMenu, int itemRowHeight) {
    mActivity = activity;
    mAppMenu = appMenu;
    mItemRowHeight = itemRowHeight;
    Resources res = mActivity.getResources();
    mAutoScrollFullVelocity = res.getDimensionPixelSize(R.dimen.auto_scroll_full_velocity);
    // If user is dragging and the popup ListView is too big to display at once,
    // mDragScrolling animator scrolls mPopup.getListView() automatically depending on
    // the user's touch position.
    mDragScrolling.setTimeListener(new TimeAnimator.TimeListener() {
        @Override
        public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
            ListPopupWindow popup = mAppMenu.getPopup();
            if (popup == null || popup.getListView() == null) return;

            // We keep both mDragScrollOffset and mDragScrollOffsetRounded because
            // the actual scrolling is by the rounded value but at the same time we also
            // want to keep the precise scroll value in float.
            mDragScrollOffset += (deltaTime * 0.001f) * mDragScrollingVelocity;
            int diff = Math.round(mDragScrollOffset - mDragScrollOffsetRounded);
            mDragScrollOffsetRounded += diff;
            popup.getListView().smoothScrollBy(diff, 0);

            // Force touch move event to highlight items correctly for the scrolled position.
            if (!Float.isNaN(mLastTouchX) && !Float.isNaN(mLastTouchY)) {
                menuItemAction(Math.round(mLastTouchX), Math.round(mLastTouchY),
                        ITEM_ACTION_HIGHLIGHT);
            }
        }
    });

    // We use medium timeout, the average of tap and long press timeouts. This is consistent
    // with ListPopupWindow#ForwardingListener implementation.
    mTapTimeout =
            (ViewConfiguration.getTapTimeout() + ViewConfiguration.getLongPressTimeout()) / 2;
    mScaledTouchSlop = ViewConfiguration.get(activity).getScaledTouchSlop();
}
 
源代码19 项目: 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);
        }
    });
}
 
源代码20 项目: 365browser   文件: AppMenuDragHelper.java
AppMenuDragHelper(Activity activity, AppMenu appMenu, int itemRowHeight) {
    mActivity = activity;
    mAppMenu = appMenu;
    mItemRowHeight = itemRowHeight;
    Resources res = mActivity.getResources();
    mAutoScrollFullVelocity = res.getDimensionPixelSize(R.dimen.auto_scroll_full_velocity);
    // If user is dragging and the popup ListView is too big to display at once,
    // mDragScrolling animator scrolls mPopup.getListView() automatically depending on
    // the user's touch position.
    mDragScrolling.setTimeListener(new TimeAnimator.TimeListener() {
        @Override
        public void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime) {
            ListPopupWindow popup = mAppMenu.getPopup();
            if (popup == null || popup.getListView() == null) return;

            // We keep both mDragScrollOffset and mDragScrollOffsetRounded because
            // the actual scrolling is by the rounded value but at the same time we also
            // want to keep the precise scroll value in float.
            mDragScrollOffset += (deltaTime * 0.001f) * mDragScrollingVelocity;
            int diff = Math.round(mDragScrollOffset - mDragScrollOffsetRounded);
            mDragScrollOffsetRounded += diff;
            popup.getListView().smoothScrollBy(diff, 0);

            // Force touch move event to highlight items correctly for the scrolled position.
            if (!Float.isNaN(mLastTouchX) && !Float.isNaN(mLastTouchY)) {
                menuItemAction(Math.round(mLastTouchX), Math.round(mLastTouchY),
                        ITEM_ACTION_HIGHLIGHT);
            }
        }
    });

    // We use medium timeout, the average of tap and long press timeouts. This is consistent
    // with ListPopupWindow#ForwardingListener implementation.
    mTapTimeout =
            (ViewConfiguration.getTapTimeout() + ViewConfiguration.getLongPressTimeout()) / 2;
    mScaledTouchSlop = ViewConfiguration.get(activity).getScaledTouchSlop();
}
 
源代码21 项目: 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);
}
 
源代码22 项目: 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;
}
 
源代码23 项目: 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);
    }
}
 
源代码24 项目: Edit-Spinner   文件: EditSpinner.java
private void initFromAttributes(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.EditSpinner, defStyleAttr, defStyleRes);

    mPopup = new ListPopupWindow(context, attrs);
    mPopup.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    mPopup.setPromptPosition(ListPopupWindow.POSITION_PROMPT_BELOW);

    Drawable selector = a.getDrawable(R.styleable.EditSpinner_dropDownSelector);
    if (selector != null) {
        mPopup.setListSelector(selector);
    }

    int dropDownAnimStyleResId = a.getResourceId(R.styleable.EditSpinner_dropDownAnimStyle, -1);
    if (dropDownAnimStyleResId > 0) {
        setDropDownAnimationStyle(dropDownAnimStyleResId);
    }

    mDropDownDrawable = a.getDrawable(R.styleable.EditSpinner_dropDownDrawable);
    int dropDownDrawableSpacing = a.getDimensionPixelOffset(R.styleable.EditSpinner_dropDownDrawableSpacing, 0);

    if (mDropDownDrawable != null) {
        int dropDownDrawableWidth = a.getDimensionPixelOffset(R.styleable.EditSpinner_dropDownDrawableWidth, -1);
        int dropDownDrawableHeight = a.getDimensionPixelOffset(R.styleable.EditSpinner_dropDownDrawableHeight, -1);
        setDropDownDrawable(mDropDownDrawable, dropDownDrawableWidth, dropDownDrawableHeight);
        setDropDownDrawableSpacing(dropDownDrawableSpacing);
    }

    // Get the anchor's id now, but the view won't be ready, so wait to actually get the
    // view and store it in mDropDownAnchorView lazily in getDropDownAnchorView later.
    // Defaults to NO_ID, in which case the getDropDownAnchorView method will simply return
    // this TextView, as a default anchoring point.
    mDropDownAnchorId = a.getResourceId(R.styleable.EditSpinner_dropDownAnchor,
            View.NO_ID);


    // For dropdown width, the developer can specify a specific width, or MATCH_PARENT
    // (for full screen width) or WRAP_CONTENT (to match the width of the anchored view).
    mPopup.setWidth(a.getLayoutDimension(R.styleable.EditSpinner_dropDownWidth,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    mPopup.setHeight(a.getLayoutDimension(R.styleable.EditSpinner_dropDownHeight,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    mPopup.setOnItemClickListener(new DropDownItemClickListener());
    mPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            mLastDismissTime = SystemClock.elapsedRealtime();
            if (mOnDismissListener != null) {
                mOnDismissListener.onDismiss();
            }
        }
    });
    a.recycle();

    mIsEditable = getKeyListener() != null;

    setFocusable(true);
    addTextChangedListener(new MyWatcher());

    Log.d(TAG, "mIsEditable = " + mIsEditable);
}
 
源代码25 项目: talk-android   文件: RecipientEditTextView.java
private void showAlternates(final DrawableRecipientChip currentChip,
                            final ListPopupWindow alternatesPopup, final int width) {
    new AsyncTask<Void, Void, ListAdapter>() {
        @Override
        protected ListAdapter doInBackground(final Void... params) {
            return createAlternatesAdapter(currentChip);
        }

        @Override
        protected void onPostExecute(final ListAdapter result) {
            if (!mAttachedToWindow) {
                return;
            }
            int line = getLayout().getLineForOffset(getChipStart(currentChip));
            int bottom;
            if (line == getLineCount() - 1) {
                bottom = 0;
            } else {
                bottom = -(int) ((mChipHeight + (2 * mLineSpacingExtra)) * (Math
                        .abs(getLineCount() - 1 - line)));
            }
            // Align the alternates popup with the left side of the View,
            // regardless of the position of the chip tapped.
            alternatesPopup.setWidth(width);
            alternatesPopup.setAnchorView(RecipientEditTextView.this);
            alternatesPopup.setVerticalOffset(bottom);
            alternatesPopup.setAdapter(result);
            alternatesPopup.setOnItemClickListener(mAlternatesListener);
            // Clear the checked item.
            mCheckedItem = -1;
            alternatesPopup.show();
            ListView listView = alternatesPopup.getListView();
            listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
            // Checked item would be -1 if the adapter has not
            // loaded the view that should be checked yet. The
            // variable will be set correctly when onCheckedItemChanged
            // is called in a separate thread.
            if (mCheckedItem != -1) {
                listView.setItemChecked(mCheckedItem, true);
                mCheckedItem = -1;
            }
        }
    }.execute((Void[]) null);
}
 
源代码26 项目: delion   文件: StripLayoutHelper.java
/**
 * Creates an instance of the {@link StripLayoutHelper}.
 * @param context         The current Android {@link Context}.
 * @param updateHost      The parent {@link LayoutUpdateHost}.
 * @param renderHost      The {@link LayoutRenderHost}.
 * @param incognito       Whether or not this tab strip is incognito.
 */
public StripLayoutHelper(Context context, LayoutUpdateHost updateHost,
        LayoutRenderHost renderHost, boolean incognito) {
    mTabOverlapWidth = TAB_OVERLAP_WIDTH_DP;
    mNewTabButtonWidth = NEW_TAB_BUTTON_WIDTH_DP;

    mRightMargin = LocalizationUtils.isLayoutRtl() ? 0 : mNewTabButtonWidth;
    mLeftMargin = LocalizationUtils.isLayoutRtl() ? mNewTabButtonWidth : 0;
    mMinTabWidth = MIN_TAB_WIDTH_DP;
    mMaxTabWidth = MAX_TAB_WIDTH_DP;
    mReorderMoveStartThreshold = REORDER_MOVE_START_THRESHOLD_DP;
    mUpdateHost = updateHost;
    mRenderHost = renderHost;
    mNewTabButton =
            new CompositorButton(context, NEW_TAB_BUTTON_WIDTH_DP, NEW_TAB_BUTTON_HEIGHT_DP);
    mNewTabButton.setResources(R.drawable.btn_tabstrip_new_tab_normal,
            R.drawable.btn_tabstrip_new_tab_pressed,
            R.drawable.btn_tabstrip_new_incognito_tab_normal,
            R.drawable.btn_tabstrip_new_incognito_tab_pressed);
    mNewTabButton.setIncognito(incognito);
    mNewTabButton.setY(NEW_TAB_BUTTON_Y_OFFSET_DP);
    mNewTabButton.setClickSlop(NEW_TAB_BUTTON_CLICK_SLOP_DP);
    Resources res = context.getResources();
    mNewTabButton.setAccessibilityDescription(
            res.getString(R.string.accessibility_toolbar_btn_new_tab),
            res.getString(R.string.accessibility_toolbar_btn_new_incognito_tab));
    mContext = context;
    mIncognito = incognito;
    mBrightness = 1.f;

    // Create tab menu
    mTabMenu = new ListPopupWindow(mContext);
    mTabMenu.setAdapter(new ArrayAdapter<String>(mContext, R.layout.bookmark_popup_item,
            new String[] {
                    mContext.getString(!mIncognito ? R.string.menu_close_all_tabs
                                                   : R.string.menu_close_all_incognito_tabs)}));
    mTabMenu.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mTabMenu.dismiss();
            if (position == ID_CLOSE_ALL_TABS) {
                mModel.closeAllTabs(false, false);
            }
        }
    });

    int menuWidth = mContext.getResources().getDimensionPixelSize(R.dimen.menu_width);
    mTabMenu.setWidth(menuWidth);
    mTabMenu.setModal(true);

    int screenWidthDp = context.getResources().getConfiguration().screenWidthDp;
    mShouldCascadeTabs = screenWidthDp >= DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP;
    mStripStacker = mShouldCascadeTabs ? mCascadingStripStacker : mScrollingStripStacker;
    mIsFirstLayoutPass = true;
}
 
源代码27 项目: delion   文件: AppMenu.java
/**
 * @return ListPopupWindow that displays all the menu options.
 */
ListPopupWindow getPopup() {
    return mPopup;
}
 
源代码28 项目: AndroidChromium   文件: StripLayoutHelper.java
/**
 * Creates an instance of the {@link StripLayoutHelper}.
 * @param context         The current Android {@link Context}.
 * @param updateHost      The parent {@link LayoutUpdateHost}.
 * @param renderHost      The {@link LayoutRenderHost}.
 * @param incognito       Whether or not this tab strip is incognito.
 */
public StripLayoutHelper(Context context, LayoutUpdateHost updateHost,
        LayoutRenderHost renderHost, boolean incognito) {
    mTabOverlapWidth = TAB_OVERLAP_WIDTH_DP;
    mNewTabButtonWidth = NEW_TAB_BUTTON_WIDTH_DP;

    mRightMargin = LocalizationUtils.isLayoutRtl() ? 0 : mNewTabButtonWidth;
    mLeftMargin = LocalizationUtils.isLayoutRtl() ? mNewTabButtonWidth : 0;
    mMinTabWidth = MIN_TAB_WIDTH_DP;
    mMaxTabWidth = MAX_TAB_WIDTH_DP;
    mReorderMoveStartThreshold = REORDER_MOVE_START_THRESHOLD_DP;
    mUpdateHost = updateHost;
    mRenderHost = renderHost;
    mNewTabButton =
            new CompositorButton(context, NEW_TAB_BUTTON_WIDTH_DP, NEW_TAB_BUTTON_HEIGHT_DP);
    mNewTabButton.setResources(R.drawable.btn_tabstrip_new_tab_normal,
            R.drawable.btn_tabstrip_new_tab_pressed,
            R.drawable.btn_tabstrip_new_incognito_tab_normal,
            R.drawable.btn_tabstrip_new_incognito_tab_pressed);
    mNewTabButton.setIncognito(incognito);
    mNewTabButton.setY(NEW_TAB_BUTTON_Y_OFFSET_DP);
    mNewTabButton.setClickSlop(NEW_TAB_BUTTON_CLICK_SLOP_DP);
    Resources res = context.getResources();
    mNewTabButton.setAccessibilityDescription(
            res.getString(R.string.accessibility_toolbar_btn_new_tab),
            res.getString(R.string.accessibility_toolbar_btn_new_incognito_tab));
    mContext = context;
    mIncognito = incognito;
    mBrightness = 1.f;

    // Create tab menu
    mTabMenu = new ListPopupWindow(mContext);
    mTabMenu.setAdapter(new ArrayAdapter<String>(mContext, R.layout.bookmark_popup_item,
            new String[] {
                    mContext.getString(!mIncognito ? R.string.menu_close_all_tabs
                                                   : R.string.menu_close_all_incognito_tabs)}));
    mTabMenu.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mTabMenu.dismiss();
            if (position == ID_CLOSE_ALL_TABS) {
                mModel.closeAllTabs(false, false);
            }
        }
    });

    int menuWidth = mContext.getResources().getDimensionPixelSize(R.dimen.menu_width);
    mTabMenu.setWidth(menuWidth);
    mTabMenu.setModal(true);

    int screenWidthDp = context.getResources().getConfiguration().screenWidthDp;
    mShouldCascadeTabs = screenWidthDp >= DeviceFormFactor.MINIMUM_TABLET_WIDTH_DP;
    mStripStacker = mShouldCascadeTabs ? mCascadingStripStacker : mScrollingStripStacker;
    mIsFirstLayoutPass = true;
}
 
源代码29 项目: AndroidChromium   文件: AppMenu.java
/**
 * @return ListPopupWindow that displays all the menu options.
 */
ListPopupWindow getPopup() {
    return mPopup;
}
 
源代码30 项目: 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();
    }

}
 
 类所在包
 同包方法