List of usage examples for android.widget ListPopupWindow setOnItemClickListener
public void setOnItemClickListener(@Nullable AdapterView.OnItemClickListener clickListener)
From source file:com.brandroidtools.filemanager.activities.PickerActivity.java
/** * Method that shows a popup with the storage volumes * * @param anchor The view on which anchor the popup *///from ww w . jav a 2 s. co m private void showStorageVolumesPopUp(View anchor) { // Create a list (but not checkable) final FileSystemStorageVolume[] volumes = StorageHelper.getStorageVolumes(PickerActivity.this); List<CheckableItem> descriptions = new ArrayList<CheckableItem>(); if (volumes != null) { int cc = volumes.length; for (int i = 0; i < cc; i++) { String desc = StorageHelper.getStorageVolumeDescription(this, volumes[i]); CheckableItem item = new CheckableItem(desc, false, false); descriptions.add(item); } } CheckableListAdapter adapter = new CheckableListAdapter(getApplicationContext(), descriptions); //Create a show the popup menu final ListPopupWindow popup = DialogHelper.createListPopupWindow(this, adapter, anchor); popup.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { popup.dismiss(); if (volumes != null) { PickerActivity.this.mNavigationFragment.changeCurrentDir(volumes[position].getPath()); } } }); popup.show(); }
From source file:com.ruesga.rview.fragments.DownloadDialogFragment.java
private void showDownloadTypeChooser(View anchor) { final ListPopupWindow popupWindow = new ListPopupWindow(getContext()); SimpleDropDownAdapter adapter = new SimpleDropDownAdapter(getContext(), mDownloadTypes, mModel.downloadType);//from ww w . ja v a 2 s .c o m 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(); }
From source file:com.android.settings.users.EditUserPhotoController.java
private void showUpdatePhotoPopup() { final boolean canTakePhoto = canTakePhoto(); final boolean canChoosePhoto = canChoosePhoto(); if (!canTakePhoto && !canChoosePhoto) { return;/*from w ww .j a v a 2 s .c om*/ } final Context context = mImageView.getContext(); final List<EditUserPhotoController.RestrictedMenuItem> items = new ArrayList<>(); if (canTakePhoto) { final String title = context.getString(R.string.user_image_take_photo); final Runnable action = new Runnable() { @Override public void run() { takePhoto(); } }; items.add(new RestrictedMenuItem(context, title, UserManager.DISALLOW_SET_USER_ICON, action)); } if (canChoosePhoto) { final String title = context.getString(R.string.user_image_choose_photo); final Runnable action = new Runnable() { @Override public void run() { choosePhoto(); } }; items.add(new RestrictedMenuItem(context, title, UserManager.DISALLOW_SET_USER_ICON, action)); } final ListPopupWindow listPopupWindow = new ListPopupWindow(context); listPopupWindow.setAnchorView(mImageView); listPopupWindow.setModal(true); listPopupWindow.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED); listPopupWindow.setAdapter(new RestrictedPopupMenuAdapter(context, items)); final int width = Math.max(mImageView.getWidth(), context.getResources().getDimensionPixelSize(R.dimen.update_user_photo_popup_min_width)); listPopupWindow.setWidth(width); listPopupWindow.setDropDownGravity(Gravity.START); listPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { listPopupWindow.dismiss(); final RestrictedMenuItem item = (RestrictedMenuItem) parent.getAdapter().getItem(position); item.doAction(); } }); listPopupWindow.show(); }
From source file:com.brandroidtools.filemanager.activities.NavigationActivity.java
/** * Method that shows a popup with a menu associated a {@link com.brandroidtools.filemanager.preferences.FileManagerSettings}. * * @param anchor The action button that was pressed * @param settings The array of settings associated with the action button */// w w w . j a v a2 s. c om private void showSettingsPopUp(View anchor, List<FileManagerSettings> settings) { //Create the adapter final MenuSettingsAdapter adapter = new MenuSettingsAdapter(this, settings); //Create a show the popup menu final ListPopupWindow popup = DialogHelper.createListPopupWindow(this, adapter, anchor); popup.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { FileManagerSettings setting = ((MenuSettingsAdapter) parent.getAdapter()).getSetting(position); final int value = ((MenuSettingsAdapter) parent.getAdapter()).getId(position); popup.dismiss(); try { if (setting.compareTo(FileManagerSettings.SETTINGS_LAYOUT_MODE) == 0) { //Need to change the layout getCurrentNavigationFragment().changeViewMode(NavigationLayoutMode.fromId(value)); } else { //Save and refresh if (setting.getDefaultValue() instanceof Enum<?>) { //Enumeration Preferences.savePreference(setting, new ObjectIdentifier() { @Override public int getId() { return value; } }, false); } else { //Boolean boolean newval = Preferences.getSharedPreferences().getBoolean(setting.getId(), ((Boolean) setting.getDefaultValue()).booleanValue()); Preferences.savePreference(setting, Boolean.valueOf(!newval), false); } getCurrentNavigationFragment().refresh(); } } catch (Exception e) { Log.e(TAG, "Error applying navigation option", e); //$NON-NLS-1$ NavigationActivity.this.mHandler.post(new Runnable() { @Override public void run() { DialogHelper.showToast(NavigationActivity.this, R.string.msgs_settings_save_failure, Toast.LENGTH_SHORT); } }); } finally { adapter.dispose(); getCurrentNavigationFragment().getCustomTitle().restoreView(); } } }); popup.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { adapter.dispose(); } }); popup.show(); }