Java Code Examples for android.widget.ListPopupWindow#show()

The following examples show how to use android.widget.ListPopupWindow#show() . 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: 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 2
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 3
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 4
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 5
Source File: SettingsActivity.java    From home-assistant-Android with GNU General Public License v3.0 4 votes vote down vote up
@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);
    }
}
 
Example 6
Source File: AdapterBookmarks.java    From SimplicityBrowser with MIT License 4 votes vote down vote up
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();
    }

}