android.widget.ListPopupWindow Java Examples

The following examples show how to use android.widget.ListPopupWindow. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransactionDetailActivity.java    From BlockExplorer with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
 
Example #2
Source File: DropdownPopupWindow.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #3
Source File: RecipientEditTextView.java    From ChipsLibrary with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #4
Source File: RecipientEditTextView.java    From talk-android with MIT License 6 votes vote down vote up
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);
}
 
Example #5
Source File: MainActivity.java    From cwac-security with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #6
Source File: EditSpinner.java    From Edit-Spinner with Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example #7
Source File: MainActivity.java    From NaviBee with GNU General Public License v3.0 6 votes vote down vote up
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);
        }
    });
}
 
Example #8
Source File: AppMenuDragHelper.java    From delion with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #9
Source File: AppMenuDragHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #10
Source File: GalleryActivity.java    From TLint with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #11
Source File: EditSpinner.java    From EditSpinner with Apache License 2.0 5 votes vote down vote up
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);
        }
    });
}
 
Example #12
Source File: AppMenuDragHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #13
Source File: AppMenu.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #14
Source File: BreadcrumbsAdapter.java    From BreadcrumbsView with MIT License 5 votes vote down vote up
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);
		}
	});
}
 
Example #15
Source File: AppMenu.java    From delion with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #16
Source File: ExplorerActivity.java    From BlockExplorer with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #17
Source File: TextChipsEditView.java    From talk-android with MIT License 5 votes vote down vote up
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));
    }
 
Example #18
Source File: AutoCompletePanel.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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();
        }
    });

}
 
Example #19
Source File: EditSpinner.java    From Edit-Spinner with Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example #20
Source File: SelectorView.java    From NovelReader with MIT License 5 votes vote down vote up
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);
}
 
Example #21
Source File: ButtonFragment.java    From holoaccent with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #22
Source File: TransactionListActivity.java    From BlockExplorer with Apache License 2.0 5 votes vote down vote up
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();
            }
        }
    });

}
 
Example #23
Source File: RecipientEditTextView.java    From ChipsLibrary with Apache License 2.0 4 votes vote down vote up
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;
      final 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();
      final ListView listView=alternatesPopup.getListView();
      listView.setChoiceMode(AbsListView.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);
}
 
Example #24
Source File: ListPopupWindowCompatKitKat.java    From guideshow with MIT License 4 votes vote down vote up
public static OnTouchListener createDragToOpenListener(Object listPopupWindow, View src) {
    return ((ListPopupWindow) listPopupWindow).createDragToOpenListener(src);
}
 
Example #25
Source File: ListPopupWindowCompatKitKat.java    From V.FlyoutTest with MIT License 4 votes vote down vote up
public static OnTouchListener createDragToOpenListener(Object listPopupWindow, View src) {
    return ((ListPopupWindow) listPopupWindow).createDragToOpenListener(src);
}
 
Example #26
Source File: ListPopupWindowCompatKitKat.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
public static OnTouchListener createDragToOpenListener(Object listPopupWindow, View src) {
    return ((ListPopupWindow) listPopupWindow).createDragToOpenListener(src);
}
 
Example #27
Source File: NiceSpinner.java    From nice-spinner with Apache License 2.0 4 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    Resources resources = getResources();
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NiceSpinner);
    int defaultPadding = resources.getDimensionPixelSize(R.dimen.one_and_a_half_grid_unit);

    setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
    setPadding(resources.getDimensionPixelSize(R.dimen.three_grid_unit), defaultPadding, defaultPadding,
            defaultPadding);
    setClickable(true);
    backgroundSelector = typedArray.getResourceId(R.styleable.NiceSpinner_backgroundSelector, R.drawable.selector);
    setBackgroundResource(backgroundSelector);
    textColor = typedArray.getColor(R.styleable.NiceSpinner_textTint, getDefaultTextColor(context));
    setTextColor(textColor);
    popupWindow = new ListPopupWindow(context);
    popupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // The selected item is not displayed within the list, so when the selected position is equal to
            // the one of the currently selected item it gets shifted to the next item.
            if (position >= selectedIndex && position < adapter.getCount()) {
                position++;
            }
            selectedIndex = position;

            if (onSpinnerItemSelectedListener != null) {
                onSpinnerItemSelectedListener.onItemSelected(NiceSpinner.this, view, position, id);
            }

            if (onItemClickListener != null) {
                onItemClickListener.onItemClick(parent, view, position, id);
            }

            if (onItemSelectedListener != null) {
                onItemSelectedListener.onItemSelected(parent, view, position, id);
            }

            adapter.setSelectedIndex(position);

            setTextInternal(adapter.getItemInDataset(position));

            dismissDropDown();
        }
    });

    popupWindow.setModal(true);

    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            if (!isArrowHidden) {
                animateArrow(false);
            }
        }
    });

    isArrowHidden = typedArray.getBoolean(R.styleable.NiceSpinner_hideArrow, false);
    arrowDrawableTint = typedArray.getColor(R.styleable.NiceSpinner_arrowTint, getResources().getColor(android.R.color.black));
    arrowDrawableResId = typedArray.getResourceId(R.styleable.NiceSpinner_arrowDrawable, R.drawable.arrow);
    dropDownListPaddingBottom =
            typedArray.getDimensionPixelSize(R.styleable.NiceSpinner_dropDownListPaddingBottom, 0);
    horizontalAlignment = PopUpTextAlignment.fromId(
            typedArray.getInt(R.styleable.NiceSpinner_popupTextAlignment, PopUpTextAlignment.CENTER.ordinal())
    );

    CharSequence[] entries = typedArray.getTextArray(R.styleable.NiceSpinner_entries);
    if (entries != null) {
        attachDataSource(Arrays.asList(entries));
    }

    typedArray.recycle();

    measureDisplayHeight();

}
 
Example #28
Source File: ListPopupWindowAssert.java    From assertj-android with Apache License 2.0 4 votes vote down vote up
public ListPopupWindowAssert(ListPopupWindow actual) {
  super(actual, ListPopupWindowAssert.class);
}
 
Example #29
Source File: AppMenu.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * @return ListPopupWindow that displays all the menu options.
 */
ListPopupWindow getPopup() {
    return mPopup;
}
 
Example #30
Source File: AppMenu.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private void setPopupOffset(
        ListPopupWindow popup, int screenRotation, Rect appRect, Rect padding) {
    popup.getAnchorView().getLocationInWindow(mTempLocation);
    int anchorViewX = mTempLocation[0];
    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 = -anchorViewX;
        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 {
        boolean anchorAtBottom = isAnchorAtBottom(mPopup.getAnchorView(), appRect);
        if (anchorAtBottom && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            // When the anchor view is at the bottom of the screen on Android N+, the menu
            // must be shifted down by the height of the anchor view in order to be displayed
            // over and above it. The framework's PopupWindow positioning changed between
            // N and M. Pre-N, setting a positive offset here shifts the menu up rather than
            // down.
            // See crbug.com/705348.
            popup.setVerticalOffset(-mNegativeSoftwareVerticalOffset + anchorHeight);
        } else {
            // Shift the menu by the height of the anchor view so that it is displayed
            // over the anchor view.
            popup.setVerticalOffset(-mNegativeSoftwareVerticalOffset - anchorHeight);
        }
    }
}