Java Code Examples for android.widget.ListPopupWindow

The following are top voted examples for showing how to use android.widget.ListPopupWindow. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: talk-android   File: RecipientEditTextView.java   View source code 8 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 2
Project: q-mail   File: RecipientSelectView.java   View source code 7 votes vote down vote up
private void initView(Context context) {
    // TODO: validator?

    alternatesPopup = new ListPopupWindow(context);
    alternatesAdapter = new AlternateRecipientAdapter(context, this);
    alternatesPopup.setAdapter(alternatesAdapter);

    // don't allow duplicates, based on equality of recipient objects, which is e-mail addresses
    allowDuplicates(false);

    // if a token is completed, pick an entry based on best guess.
    // Note that we override performCompletion, so this doesn't actually do anything
    performBestGuess(true);

    adapter = new RecipientAdapter(context);
    setAdapter(adapter);

    setLongClickable(true);
}
 
Example 3
Project: rview   File: DownloadDialogFragment.java   View source code 7 votes vote down vote up
private void showDownloadTypeChooser(View anchor) {
    //noinspection ConstantConditions
    final ListPopupWindow popupWindow = new ListPopupWindow(getContext());
    SimpleDropDownAdapter<Integer> adapter = new SimpleDropDownAdapter<>(
            getContext(), mDownloadTypes, mModel.downloadType);
    popupWindow.setAnchorView(anchor);
    popupWindow.setAdapter(adapter);
    popupWindow.setContentWidth(adapter.measureContentWidth());
    popupWindow.setOnItemClickListener((parent, view, position, id) -> {
        popupWindow.dismiss();

        // Update the view
        mModel.downloadType = mDownloadTypes.get(position);
        mBinding.downloadCommands
                .from(mDownloadCommands.get(mModel.downloadType))
                .update();
        mBinding.setModel(mModel);
        mBinding.executePendingBindings();
    });
    popupWindow.setModal(true);
    popupWindow.show();
}
 
Example 4
Project: ESCAPE   File: TaskListFragment.java   View source code 7 votes vote down vote up
private void initPopup() {
	View menuItemView = getActivity().findViewById(R.id.pick_category);
	listPopupWindow = new ListPopupWindow(getActivity());
	listPopupWindow.setAnchorView(menuItemView);
	listPopupWindow.setModal(true);
	listPopupWindow.setWidth(categoryListWidth);
	listPopupWindow.setHeight(ListPopupWindow.WRAP_CONTENT);
	listPopupWindow
			.setOnDismissListener(new PopupWindow.OnDismissListener() {
				@Override
				public void onDismiss() {
					if (ourListAdapter != null)
						ourListAdapter.notifyDataSetChanged();
				}
			});
}
 
Example 5
Project: Edit-Spinner   File: EditSpinner.java   View source code 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 6
Project: K9-MailClient   File: RecipientSelectView.java   View source code 6 votes vote down vote up
private void initView(Context context) {
    // TODO: validator?

    alternatesPopup = new ListPopupWindow(context);
    alternatesAdapter = new AlternateRecipientAdapter(context, this);
    alternatesPopup.setAdapter(alternatesAdapter);

    // don't allow duplicates, based on equality of recipient objects, which is e-mail addresses
    allowDuplicates(false);

    // if a token is completed, pick an entry based on best guess.
    // Note that we override performCompletion, so this doesn't actually do anything
    performBestGuess(true);

    adapter = new RecipientAdapter(context);
    setAdapter(adapter);

    setLongClickable(true);
}
 
Example 7
Project: PopupList   File: ListUtils.java   View source code 6 votes vote down vote up
public static int getVerticalOffset(ListPopupWindow popupWindow, View anchorView, int position, int contentHeight) {
    final int shadow = calculateVerticalShadow(popupWindow);
    int offset = -shadow;

    if ((position & PopupGravity.BOTTOM) == PopupGravity.BOTTOM || (position & PopupDirection.DOWN) == PopupDirection.DOWN) {
        offset += 0;
    }

    if ((position & PopupGravity.TOP) == PopupGravity.TOP) {
        offset += -anchorView.getHeight();
    }

    if ((position & PopupGravity.CENTER_VERTICAL) == PopupGravity.CENTER_VERTICAL || (position & PopupGravity.CENTER) == PopupGravity.CENTER) {
        offset += -anchorView.getHeight() / 2;
    }

    if ((position & PopupDirection.UP) == PopupDirection.UP) {
        offset += -contentHeight - anchorView.getHeight() - (2 * shadow);
    }

    return offset;
}
 
Example 8
Project: PopupList   File: ListUtils.java   View source code 6 votes vote down vote up
public static int getHorizontalOffset(ListPopupWindow popupWindow, View anchorView, int position, int contentWidth) {
    final int shadow = calculateHorizontalShadow(popupWindow);
    int offset = -shadow;

    if ((position & PopupGravity.LEFT) == PopupGravity.LEFT) {
        offset += 0;
    }

    if ((position & PopupGravity.RIGHT) == PopupGravity.RIGHT) {
        offset += anchorView.getWidth();
    }

    if ((position & PopupGravity.CENTER_HORIZONTAL) == PopupGravity.CENTER_HORIZONTAL || (position & PopupGravity.CENTER) == PopupGravity.CENTER) {
        offset += anchorView.getWidth() / 2;
    }

    if ((position & PopupDirection.LEFT) == PopupDirection.LEFT) {
        offset += -contentWidth;
    }

    return offset;
}
 
Example 9
Project: PopupList   File: PopupList.java   View source code 6 votes vote down vote up
private void setupList() {
    mPopup = new ListPopupWindow(mContext);
    mPopup.setAdapter(mAdapter);
    mPopup.setAnchorView(mAnchorView);
    mContentWidth = ListUtils.measureListContentWidth(mAdapter, mContext);
    mContentHeight = ListUtils.measureListContentHeight(mAdapter, mContext);
    mPopup.setContentWidth(mContentWidth);
    mPopup.setModal(mIsModal);
    mPopup.setOnDismissListener(mOnDismissListener);
    mPopup.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (mOnPopupListItemListener != null)
                mOnPopupListItemListener.onPopupListItemClicked(new PopupItem(mAdapter.getItem(position)));
            mPopup.dismiss();
        }
    });

    if (mAnimationStyle != -1) {
        mPopup.setAnimationStyle(mAnimationStyle);
    }
}
 
Example 10
Project: 365browser   File: DropdownPopupWindow.java   View source code 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 11
Project: itsnat_droid   File: ClassDescView_widget_AutoCompleteTextView.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected void init()
{
    super.init();

    addAttrDescAN(new AttrDescView_widget_AutoCompleteTextView_completionHint(this));
    addAttrDescAN(new AttrDescView_widget_AutoCompleteTextView_completionHintView(this));
    addAttrDescAN(new AttrDescReflecMethodInt(this, "completionThreshold", "setThreshold", 2));
    addAttrDescAN(new AttrDescReflecMethodId(this, "dropDownAnchor", -1));
    addAttrDescAN(new AttrDescReflecMethodDimensionWithNameInt(this, "dropDownHeight", (float) ViewGroup.LayoutParams.WRAP_CONTENT));
    addAttrDescAN(new AttrDescReflecMethodDimensionIntFloor(this, "dropDownHorizontalOffset", 0.0f));
    addAttrDescAN(new AttrDescReflecFieldMethodDrawable(this, "dropDownSelector", "mPopup", ListPopupWindow.class, "setListSelector", null)); // Hay un background por defecto de Android en ListPopupWindow aunque parece que por defecto se pone un null si no hay atributo
    addAttrDescAN(new AttrDescReflecMethodDimensionIntFloor(this, "dropDownVerticalOffset", 0.0f));
    addAttrDescAN(new AttrDescReflecMethodDimensionWithNameInt(this, "dropDownWidth", (float) ViewGroup.LayoutParams.WRAP_CONTENT));
    addAttrDescAN(new AttrDescReflecMethodDrawable(this, "popupBackground", "setDropDownBackgroundDrawable", "@null"));
}
 
Example 12
Project: musicalgps   File: RegionEditor.java   View source code 6 votes vote down vote up
@Override
public void onClick(View v) {
	//TODO: refactor/redesign
   	final int regionId = v.getId();
   	final List<Integer> listsRegionsId = mRegionsDB.getAllThemesIds();
    final ListPopupWindow listThemesPopupWindow = new ListPopupWindow(mActivity);
    listThemesPopupWindow.setAdapter(new ArrayAdapter<String>(mActivity, R.layout.list_item_theme, mRegionsDB.getAllThemesNames()));
    listThemesPopupWindow.setModal(true);
       listThemesPopupWindow.setAnchorView(v);
    OnItemClickListener itemClickListener = new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
	            int position, long id) {
        	changeTheme(regionId, listsRegionsId.get(position));
        	listThemesPopupWindow.dismiss();
        	((EditorActivity)mActivity).refreshTable();
	        }	    	
		};
    listThemesPopupWindow.setOnItemClickListener(itemClickListener); 
    listThemesPopupWindow.show();		
}
 
Example 13
Project: sms_DualCard   File: RecipientEditTextView.java   View source code 6 votes vote down vote up
private void showAddress(final RecipientChip currentChip, final ListPopupWindow popup,
        int width, Context context) {
    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 14
Project: ChipsLibrary   File: RecipientEditTextView.java   View source code 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 15
Project: cwac-security   File: MainActivity.java   View source code 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 16
Project: ESCAPE   File: ExpandableEventListFragment.java   View source code 6 votes vote down vote up
private void initPopup() {
	View menuItemView = getActivity().findViewById(R.id.pick_category);
	listPopupWindow = new ListPopupWindow(getActivity());
	listPopupWindow.setAnchorView(menuItemView);
	listPopupWindow.setModal(true);
	listPopupWindow.setWidth(categoryListWidth);
	listPopupWindow.setHeight(ListPopupWindow.WRAP_CONTENT);
	listPopupWindow
			.setOnDismissListener(new PopupWindow.OnDismissListener() {
				@Override
				public void onDismiss() {
					if (listAdapter != null)
						listAdapter.notifyDataSetChanged();
				}
			});
}
 
Example 17
Project: Calendar_lunar   File: RecipientEditTextView.java   View source code 6 votes vote down vote up
private void showAddress(final RecipientChip currentChip, final ListPopupWindow popup,
        int width, Context context) {
    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 18
Project: mobile-client   File: TracksDropdownFragment.java   View source code 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
		Bundle savedInstanceState) {
	mRootView = (ViewGroup) inflater.inflate(
			R.layout.fragment_tracks_dropdown, null);

	mTitle = (TextView) mRootView.findViewById(R.id.track_title);
	mAbstract = (TextView) mRootView.findViewById(R.id.track_abstract);

	mRootView.setOnClickListener(new View.OnClickListener() {
		public void onClick(View view) {
			mListPopupWindow = new ListPopupWindow(getActivity());
			mListPopupWindow.setAdapter(mAdapter);
			mListPopupWindow.setModal(true);
			mListPopupWindow.setContentWidth(400);
			mListPopupWindow.setAnchorView(mRootView);
			mListPopupWindow
					.setOnItemClickListener(TracksDropdownFragment.this);
			mListPopupWindow.show();
			mListPopupWindow
					.setOnDismissListener(TracksDropdownFragment.this);
		}
	});

	return mRootView;
}
 
Example 19
Project: mobile-client   File: TracksDropdownFragment.java   View source code 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
		Bundle savedInstanceState) {
	mRootView = (ViewGroup) inflater.inflate(
			R.layout.fragment_tracks_dropdown, null);

	mTitle = (TextView) mRootView.findViewById(R.id.track_title);
	mAbstract = (TextView) mRootView.findViewById(R.id.track_abstract);

	mRootView.setOnClickListener(new View.OnClickListener() {
		public void onClick(View view) {
			mListPopupWindow = new ListPopupWindow(getActivity());
			mListPopupWindow.setAdapter(mAdapter);
			mListPopupWindow.setModal(true);
			mListPopupWindow.setContentWidth(400);
			mListPopupWindow.setAnchorView(mRootView);
			mListPopupWindow
					.setOnItemClickListener(TracksDropdownFragment.this);
			mListPopupWindow.show();
			mListPopupWindow
					.setOnDismissListener(TracksDropdownFragment.this);
		}
	});

	return mRootView;
}
 
Example 20
Project: google-iosched   File: TracksDropdownFragment.java   View source code 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    mRootView = (ViewGroup) inflater.inflate(R.layout.fragment_tracks_dropdown, null);
    mTitle = (TextView) mRootView.findViewById(R.id.track_title);
    mAbstract = (TextView) mRootView.findViewById(R.id.track_abstract);

    mRootView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            mListPopupWindow = new ListPopupWindow(getActivity());
            mListPopupWindow.setAdapter(mAdapter);
            mListPopupWindow.setModal(true);
            mListPopupWindow.setContentWidth(
                    getResources().getDimensionPixelSize(R.dimen.track_dropdown_width));
            mListPopupWindow.setAnchorView(mRootView);
            mListPopupWindow.setOnItemClickListener(TracksDropdownFragment.this);
            mListPopupWindow.show();
            mListPopupWindow.setOnDismissListener(TracksDropdownFragment.this);
        }
    });
    return mRootView;
}
 
Example 21
Project: iosched2013   File: TracksDropdownFragment.java   View source code 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    mRootView = (ViewGroup) inflater.inflate(R.layout.fragment_tracks_dropdown, null);
    mIcon = (ImageView) mRootView.findViewById(R.id.track_icon);
    mTitle = (TextView) mRootView.findViewById(R.id.track_title);
    mAbstract = (TextView) mRootView.findViewById(R.id.track_abstract);

    mRootView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            mListPopupWindow = new ListPopupWindow(getActivity());
            mListPopupWindow.setAdapter(mAdapter);
            mListPopupWindow.setModal(true);
            mListPopupWindow.setContentWidth(
                    getResources().getDimensionPixelSize(R.dimen.track_dropdown_width));
            mListPopupWindow.setAnchorView(mRootView);
            mListPopupWindow.setOnItemClickListener(TracksDropdownFragment.this);
            mListPopupWindow.show();
            mListPopupWindow.setOnDismissListener(TracksDropdownFragment.this);
        }
    });
    return mRootView;
}
 
Example 22
Project: NovelReader   File: SelectorView.java   View source code 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 23
Project: chromium-for-android-56-debug-video   File: AppMenu.java   View source code 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 24
Project: chromium-for-android-56-debug-video   File: AppMenuDragHelper.java   View source code 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 25
Project: aos-MediaLib   File: ActionBarSubmenu.java   View source code 5 votes vote down vote up
/*******************************************************************
** ActionBarSubmenu API
*******************************************************************/

public ActionBarSubmenu(Context context, LayoutInflater inflater, View anchor) {
    mContext = context;

    mItemList = new ArrayList<SubmenuItemData>();
    mSelectedPosition = 0;   // default value
    mSubmenuItemTitleMaxWidth = 0;

    mAdapter = new ActionBarSubmenuAdapter(inflater);

    mPopupWindow = new ListPopupWindow(context, null);
    mPopupWindow.setAdapter(mAdapter);
    mPopupWindow.setModal(true);
    mPopupWindow.setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(context,R.color.primary_material_dark)));
    mPopupWindow.setAnchorView(anchor);
    mPopupWindow.setOnItemClickListener(this);

    // Get the size of the font used to display the submenu items
    TypedValue typedValue = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.textAppearanceLarge, typedValue, true);
    int[] attribute = new int[] { android.R.attr.textSize };
    TypedArray array = context.obtainStyledAttributes(typedValue.resourceId, attribute);
    mSubmenuFontSize = array.getDimensionPixelSize(0, -1);
    array.recycle();

    // Get the size of the radio button bitmap
    mRadioButtonWidth = context.getResources().getDimensionPixelSize(R.dimen.radio_button_width);
}
 
Example 26
Project: Edit-Spinner   File: EditSpinner.java   View source code 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 27
Project: talk-android   File: TextChipsEditView.java   View source code 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 28
Project: YinjiImageEditor   File: PhotoMutiSelectActivity.java   View source code 5 votes vote down vote up
/** 创建弹出的ListView */
private void createPopupFolderList(int width, int height) {
    mFolderPopupWindow = new ListPopupWindow(this);
    mFolderPopupWindow.setBackgroundDrawable(null);
    mFolderPopupWindow.setAdapter(mImageFolderAdapter);
    mFolderPopupWindow.setContentWidth(width);
    mFolderPopupWindow.setWidth(width);  //如果不设置,就是 AnchorView 的宽度
    mFolderPopupWindow.setHeight(height * 5 / 8);
    mFolderPopupWindow.setAnchorView(mFooterBar);  //ListPopupWindow总会相对于这个View
    mFolderPopupWindow.setModal(false);  //是否为模态,影响返回键的处理
    mFolderPopupWindow.setAnimationStyle(R.style.popupwindow_anim_style);
    mFolderPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            backgroundAlpha(1.0f);
        }
    });
    mFolderPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            mImageFolderAdapter.setSelectIndex(position);
            imagePicker.setCurrentImageFolderPosition(position);
            mFolderPopupWindow.dismiss();
            ImageFolder imageFolder = (ImageFolder) adapterView.getAdapter().getItem(position);
            if (null != imageFolder) {
                mImageGridAdapter.refreshData(imageFolder.images);
                mBtnDir.setText(imageFolder.name);
            }
            gv_photo_list.smoothScrollToPosition(0);//滑动到顶部
        }
    });
}
 
Example 29
Project: truth-android   File: ListPopupWindowSubject.java   View source code 5 votes vote down vote up
public static SubjectFactory<ListPopupWindowSubject, ListPopupWindow> type() {
  return new SubjectFactory<ListPopupWindowSubject, ListPopupWindow>() {
    @Override
    public ListPopupWindowSubject getSubject(FailureStrategy fs, ListPopupWindow that) {
      return new ListPopupWindowSubject(fs, that);
    }
  };
}
 
Example 30
Project: AndroidChromium   File: AppMenu.java   View source code 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 31
Project: AndroidChromium   File: AppMenuDragHelper.java   View source code 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 32
Project: EditSpinner   File: EditSpinner.java   View source code 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 33
Project: Vafrinn   File: AppMenu.java   View source code 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 (mIsByHardwareButton) {
        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 34
Project: Vafrinn   File: AppMenuDragHelper.java   View source code 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 35
Project: 365browser   File: AppMenuDragHelper.java   View source code 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 36
Project: TLint   File: GalleryActivity.java   View source code 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 37
Project: FlexibleAdapter   File: BottomSheetSectionDialog.java   View source code 5 votes vote down vote up
private void createPopUps() {
    //Create the Adapter
    if (mAdapterReference == null) {
        mAdapterItemType = new ArrayAdapter(getContext(), R.layout.reference_spinner_item, new String[]{"Simple Item", "Expandable", "Expandable Section", "Section"});
        mAdapterReference = new ArrayAdapter(getContext(), R.layout.reference_spinner_item, getListener().getReferenceList());
    }
    //Setting up the popups
    Log.d(TAG, "Setting up the Popups");
    //Item Type
    mPopupItemType = new ListPopupWindow(getContext());
    mPopupItemType.setAnchorView(mBottomSheetDialog.findViewById(R.id.select_item_type));
    mPopupItemType.setModal(true);
    mPopupItemType.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
    mPopupItemType.setAnimationStyle(android.R.style.Animation_Dialog);
    mPopupItemType.setAdapter(mAdapterItemType);
    mPopupItemType.setVerticalOffset(-100);

    //Header Reference
    mPopupReference = new ListPopupWindow(getContext());
    mPopupReference.setAnchorView(mBottomSheetDialog.findViewById(R.id.select_reference_button));
    mPopupReference.setModal(true);
    mPopupReference.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED);
    mPopupReference.setAnimationStyle(android.R.style.Animation_Dialog);
    mPopupReference.setAdapter(mAdapterReference);
    mPopupReference.setVerticalOffset(-100);
    if (mAdapterReference.getCount() > 6)
        mPopupReference.setHeight(getResources().getDimensionPixelSize(R.dimen.popup_max_height));
}
 
Example 38
Project: GreenMatter   File: ButtonFragment.java   View source code 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 39
Project: FullRobolectricTestSample   File: ListPopupWindowTest.java   View source code 5 votes vote down vote up
@Test
public void show_setsLastListPopupWindow() throws Exception {
  Context context = Robolectric.application;
  ListPopupWindow popupWindow = new ListPopupWindow(context);
  assertThat(ShadowListPopupWindow.getLatestListPopupWindow()).isNull();
  popupWindow.setAnchorView(new View(context));
  popupWindow.show();
  assertThat(ShadowListPopupWindow.getLatestListPopupWindow()).isSameAs(popupWindow);
}
 
Example 40
Project: sms_DualCard   File: RecipientEditTextView.java   View source code 5 votes vote down vote up
public RecipientEditTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    setChipDimensions(context, attrs);
    if (sSelectedTextColor == -1) {
        sSelectedTextColor = context.getResources().getColor(android.R.color.white);
    }
    mAlternatesPopup = new ListPopupWindow(context);
    mAddressPopup = new ListPopupWindow(context);
    mCopyDialog = new Dialog(context);
    mAlternatesListener = new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView,View view, int position,
                long rowId) {
            mAlternatesPopup.setOnItemClickListener(null);
            replaceChip(mSelectedChip, ((RecipientAlternatesAdapter) adapterView.getAdapter())
                    .getRecipientEntry(position));
            Message delayed = Message.obtain(mHandler, DISMISS);
            delayed.obj = mAlternatesPopup;
            mHandler.sendMessageDelayed(delayed, DISMISS_DELAY);
            clearComposingText();
        }
    };
    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);
    mGestureDetector = new GestureDetector(context, this);
    setOnEditorActionListener(this);
}