Search in sources :

Example 56 with PopupMenu

use of android.support.v7.widget.PopupMenu in project RoMote by wseemann.

the class AltMainActivity method showMenu.

private void showMenu(final View v) {
    PopupMenu popup = new PopupMenu(this, v);
    // This activity implements OnMenuItemClickListener
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Device device = (Device) v.getTag();
            switch(item.getItemId()) {
                case R.id.action_info:
                    Intent intent = new Intent(AltMainActivity.this, DeviceInfoActivity.class);
                    intent.putExtra("serial_number", device.getSerialNumber());
                    intent.putExtra("host", device.getHost());
                    startActivity(intent);
                    return true;
                case R.id.action_unpair:
                    PreferenceUtils.setConnectedDevice(AltMainActivity.this, "");
                    DBUtils.removeDevice(AltMainActivity.this, device.getSerialNumber());
                    refreshList(false);
                    return true;
                default:
                    return false;
            }
        }
    });
    popup.inflate(R.menu.device_menu);
    Device device = (Device) v.getTag();
    if (DBUtils.getDevice(this, device.getSerialNumber()) == null) {
        popup.getMenu().removeItem(R.id.action_unpair);
    }
    popup.show();
}
Also used : Device(com.jaku.model.Device) MenuItem(android.view.MenuItem) Intent(android.content.Intent) PopupMenu(android.support.v7.widget.PopupMenu)

Example 57 with PopupMenu

use of android.support.v7.widget.PopupMenu in project edx-app-android by edx.

the class EditUserProfileFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    viewHolder = new ViewHolder(view);
    viewHolder.profileImageProgress.setVisibility(View.GONE);
    viewHolder.username.setText(username);
    viewHolder.username.setContentDescription(ResourceUtil.getFormattedString(getResources(), R.string.profile_username_description, "username", username));
    final IconDrawable icon = new IconDrawable(getActivity(), FontAwesomeIcons.fa_camera).colorRes(getActivity(), R.color.disableable_button_text).sizeRes(getActivity(), R.dimen.fa_x_small).tint(// IconDrawable is tinted by default, but we don't want it to be tinted here
    null);
    TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(viewHolder.changePhoto, icon, null, null, null);
    viewHolder.changePhoto.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final PopupMenu popup = new PopupMenu(getActivity(), v);
            popup.getMenuInflater().inflate(R.menu.change_photo, popup.getMenu());
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

                public boolean onMenuItemClick(MenuItem item) {
                    switch(item.getItemId()) {
                        case R.id.take_photo:
                            {
                                startActivityForResult(helper.createCaptureIntent(getActivity()), CAPTURE_PHOTO_REQUEST);
                                break;
                            }
                        case R.id.choose_photo:
                            {
                                final Intent galleryIntent = new Intent().setType("image/*").setAction(Intent.ACTION_GET_CONTENT);
                                startActivityForResult(galleryIntent, CHOOSE_PHOTO_REQUEST);
                                break;
                            }
                        case R.id.remove_photo:
                            {
                                final Task task = new DeleteAccountImageTask(getActivity(), username);
                                task.setProgressDialog(viewHolder.profileImageProgress);
                                executePhotoTask(task);
                                break;
                            }
                    }
                    return true;
                }
            });
            popup.show();
        }
    });
    setData(account, formDescription);
}
Also used : Task(org.edx.mobile.task.Task) DeleteAccountImageTask(org.edx.mobile.user.DeleteAccountImageTask) GetProfileFormDescriptionTask(org.edx.mobile.user.GetProfileFormDescriptionTask) SetAccountImageTask(org.edx.mobile.user.SetAccountImageTask) DeleteAccountImageTask(org.edx.mobile.user.DeleteAccountImageTask) IconDrawable(com.joanzapata.iconify.IconDrawable) MenuItem(android.view.MenuItem) Intent(android.content.Intent) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) View(android.view.View) TextView(android.widget.TextView) IconImageView(com.joanzapata.iconify.widget.IconImageView) PopupMenu(android.support.v7.widget.PopupMenu)

Example 58 with PopupMenu

use of android.support.v7.widget.PopupMenu in project Osmand by osmandapp.

the class ItemViewHolder method contextMenu.

protected void contextMenu(View v, final IndexItem indexItem, final DownloadResourceGroup parentOptional) {
    final PopupMenu optionsMenu = new PopupMenu(context, v);
    MenuItem item;
    final File fl = indexItem.getTargetFile(context.getMyApplication());
    if (fl.exists()) {
        item = optionsMenu.getMenu().add(R.string.shared_string_remove).setIcon(context.getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark));
        item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                LocalIndexType tp = LocalIndexType.MAP_DATA;
                if (indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) {
                    tp = LocalIndexType.TILES_DATA;
                } else if (indexItem.getType() == DownloadActivityType.ROADS_FILE) {
                    tp = LocalIndexType.MAP_DATA;
                } else if (indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) {
                    tp = LocalIndexType.SRTM_DATA;
                } else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE) {
                    tp = LocalIndexType.MAP_DATA;
                } else if (indexItem.getType() == DownloadActivityType.FONT_FILE) {
                    tp = LocalIndexType.FONT_DATA;
                } else if (indexItem.getType() == DownloadActivityType.VOICE_FILE) {
                    tp = indexItem.getBasename().contains("tts") ? LocalIndexType.TTS_VOICE_DATA : LocalIndexType.VOICE_DATA;
                }
                final LocalIndexInfo info = new LocalIndexInfo(tp, fl, false, context.getMyApplication());
                AlertDialog.Builder confirm = new AlertDialog.Builder(context);
                confirm.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        new LocalIndexOperationTask(context, null, LocalIndexOperationTask.DELETE_OPERATION).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, info);
                    }
                });
                confirm.setNegativeButton(R.string.shared_string_no, null);
                String fn = FileNameTranslationHelper.getFileName(context, context.getMyApplication().getRegions(), indexItem.getVisibleName(context, context.getMyApplication().getRegions()));
                confirm.setMessage(context.getString(R.string.delete_confirmation_msg, fn));
                confirm.show();
                return true;
            }
        });
    }
    item = optionsMenu.getMenu().add(R.string.shared_string_download).setIcon(context.getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_import));
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            download(indexItem, parentOptional);
            return true;
        }
    });
    optionsMenu.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) LocalIndexOperationTask(net.osmand.plus.download.ui.LocalIndexesFragment.LocalIndexOperationTask) MenuItem(android.view.MenuItem) LocalIndexType(net.osmand.plus.activities.LocalIndexHelper.LocalIndexType) OnClickListener(android.view.View.OnClickListener) LocalIndexInfo(net.osmand.plus.activities.LocalIndexInfo) File(java.io.File) PopupMenu(android.support.v7.widget.PopupMenu)

Example 59 with PopupMenu

use of android.support.v7.widget.PopupMenu in project Osmand by osmandapp.

the class DashWaypointsFragment method selectTargetModel.

private void selectTargetModel(final TargetPoint point, final View view) {
    final PopupMenu optionsMenu = new PopupMenu(getActivity(), view);
    DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
    MenuItem item;
    // item = optionsMenu.getMenu().add(
    // R.string.shared_string_add_to_favorites).setIcon(getMyApplication().getIconsCache().
    // getIcon(R.drawable.ic_action_fav_dark));
    // item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
    // @Override
    // public boolean onMenuItemClick(MenuItem item) {
    // Bundle args = new Bundle();
    // Dialog dlg = FavoriteDialogs.createAddFavouriteDialog(getActivity(), args);
    // dlg.show();
    // FavoriteDialogs.prepareAddFavouriteDialog(getActivity(), dlg, args, model.getLatitude(), model.getLongitude(),
    // model.getOriginalPointDescription());
    // return true;
    // }
    // });
    final boolean target = point == getMyApplication().getTargetPointsHelper().getPointToNavigate();
    if (SHOW_ALL && getMyApplication().getTargetPointsHelper().getIntermediatePoints().size() > 0) {
        final List<TargetPoint> allTargets = getMyApplication().getTargetPointsHelper().getIntermediatePointsWithTarget();
        if (point.index > 0 || target) {
            final int ind = target ? allTargets.size() - 1 : point.index;
            item = optionsMenu.getMenu().add(R.string.waypoint_visit_before).setIcon(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_up_dark));
            item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    TargetPoint remove = allTargets.remove(ind - 1);
                    allTargets.add(ind, remove);
                    getMyApplication().getTargetPointsHelper().reorderAllTargetPoints(allTargets, true);
                    setupView();
                    return true;
                }
            });
        }
        if (!target) {
            item = optionsMenu.getMenu().add(R.string.waypoint_visit_after).setIcon(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_down_dark));
            item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    TargetPoint remove = allTargets.remove(point.index + 1);
                    allTargets.add(point.index, remove);
                    getMyApplication().getTargetPointsHelper().reorderAllTargetPoints(allTargets, true);
                    setupView();
                    return true;
                }
            });
        }
    }
    item = optionsMenu.getMenu().add(R.string.shared_string_remove).setIcon(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark));
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            deletePointConfirm(point, view);
            return true;
        }
    });
    optionsMenu.show();
}
Also used : MenuItem(android.view.MenuItem) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) PopupMenu(android.support.v7.widget.PopupMenu)

Example 60 with PopupMenu

use of android.support.v7.widget.PopupMenu in project Osmand by osmandapp.

the class SearchPOIActivity method showOptionsMenu.

private void showOptionsMenu(View v) {
    // Show menu with search all, name finder, name finder poi
    IconsCache iconsCache = getMyApplication().getIconsCache();
    final PopupMenu optionsMenu = new PopupMenu(this, v);
    final PoiUIFilter f = this.filter;
    MenuItem item = optionsMenu.getMenu().add(R.string.shared_string_edit).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark));
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            PoiUIFilter custom = getMyApplication().getPoiFilters().getCustomPOIFilter();
            custom.replaceWithPoiFilter(f);
            showEditActivity(custom);
            return true;
        }
    });
    addFilter(optionsMenu, getString(R.string.shared_string_is_open));
    addFilter(optionsMenu, getString(R.string.shared_string_is_open_24_7));
    Map<String, PoiType> poiAdditionals = f.getPoiAdditionals();
    if (poiAdditionals != null) {
        TreeMap<String, PoiType> adds = new TreeMap<String, PoiType>();
        for (PoiType vtype : poiAdditionals.values()) {
            if (vtype.isTopVisible()) {
                adds.put(vtype.getTranslation().replace(' ', ':').toLowerCase(), vtype);
            }
        }
        for (String vtype : adds.keySet()) {
            addFilter(optionsMenu, vtype);
        }
    }
    optionsMenu.show();
}
Also used : OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) PoiType(net.osmand.osm.PoiType) MenuItem(android.view.MenuItem) IconsCache(net.osmand.plus.IconsCache) TreeMap(java.util.TreeMap) PopupMenu(android.support.v7.widget.PopupMenu) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Aggregations

PopupMenu (android.support.v7.widget.PopupMenu)142 MenuItem (android.view.MenuItem)116 View (android.view.View)86 TextView (android.widget.TextView)63 RecyclerView (android.support.v7.widget.RecyclerView)54 ImageView (android.widget.ImageView)40 Intent (android.content.Intent)32 PopupMenu (android.widget.PopupMenu)31 List (java.util.List)27 ArrayList (java.util.ArrayList)26 MenuInflater (android.view.MenuInflater)23 Menu (android.view.Menu)22 Bundle (android.os.Bundle)20 LayoutInflater (android.view.LayoutInflater)20 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)20 Context (android.content.Context)18 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)18 AdapterView (android.widget.AdapterView)17 DialogInterface (android.content.DialogInterface)16 ViewGroup (android.view.ViewGroup)15