Example usage for android.widget ListPopupWindow show

List of usage examples for android.widget ListPopupWindow show

Introduction

In this page you can find the example usage for android.widget ListPopupWindow show.

Prototype

@Override
public void show() 

Source Link

Document

Show the popup list.

Usage

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
 *///  w ww  .j  a v a2s. c om
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 w w  w.j  a v  a2s. 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:android.support.v7ox.widget.ActivityChooserView.java

/**
 * Shows the popup no matter if it was already showing.
 *
 * @param maxActivityCount The max number of activities to display.
 *//*from   w w  w .j  av a2  s  .  c  o m*/
private void showPopupUnchecked(int maxActivityCount) {
    if (mAdapter.getDataModel() == null) {
        throw new IllegalStateException("No data model. Did you call #setDataModel?");
    }

    getViewTreeObserver().addOnGlobalLayoutListener(mOnGlobalLayoutListener);

    final boolean defaultActivityButtonShown = mDefaultActivityButton.getVisibility() == VISIBLE;

    final int activityCount = mAdapter.getActivityCount();
    final int maxActivityCountOffset = defaultActivityButtonShown ? 1 : 0;
    if (maxActivityCount != ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_UNLIMITED
            && activityCount > maxActivityCount + maxActivityCountOffset) {
        mAdapter.setShowFooterView(true);
        mAdapter.setMaxActivityCount(maxActivityCount - 1);
    } else {
        mAdapter.setShowFooterView(false);
        mAdapter.setMaxActivityCount(maxActivityCount);
    }

    ListPopupWindow popupWindow = getListPopupWindow();
    if (!popupWindow.isShowing()) {
        if (mIsSelectingDefaultActivity || !defaultActivityButtonShown) {
            mAdapter.setShowDefaultActivity(true, defaultActivityButtonShown);
        } else {
            mAdapter.setShowDefaultActivity(false, false);
        }
        final int contentWidth = Math.min(mAdapter.measureContentWidth(), mListPopupMaxWidth);
        popupWindow.setContentWidth(contentWidth);
        popupWindow.show();
        if (mProvider != null) {
            mProvider.subUiVisibilityChanged(true);
        }
        popupWindow.getListView().setContentDescription(
                getContext().getString(R.string.abc_activitychooserview_choose_application));
    }
}

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  w  w. j  a va2s  .  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  a 2s  .  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();
}