Search in sources :

Example 61 with PopupMenu

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

the class SearchPoiFilterFragment 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(getActivity(), v);
    MenuItem item = optionsMenu.getMenu().add(R.string.poi_filter_custom_filter).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_filter_dark));
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            PoiUIFilter filter = getApp().getPoiFilters().getCustomPOIFilter();
            filter.clearFilter();
            showFilterActivity(filter.getFilterId());
            return true;
        }
    });
    optionsMenu.show();
}
Also used : MenuItem(android.view.MenuItem) IconsCache(net.osmand.plus.IconsCache) PopupMenu(android.support.v7.widget.PopupMenu) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Example 62 with PopupMenu

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

the class WikivoyageArticleDialogFragment method showPopupLangMenu.

private void showPopupLangMenu(View view) {
    if (langs == null) {
        return;
    }
    final PopupMenu popup = new PopupMenu(view.getContext(), view, Gravity.END);
    for (final String lang : langs) {
        MenuItem item = popup.getMenu().add(lang);
        item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                if (!selectedLang.equals(lang)) {
                    selectedLang = lang;
                    populateArticle();
                }
                return true;
            }
        });
    }
    popup.show();
}
Also used : MenuItem(android.view.MenuItem) PopupMenu(android.support.v7.widget.PopupMenu)

Example 63 with PopupMenu

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

the class ContextMenuCardDialogFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.context_menu_card_dialog, container, false);
    AndroidUtils.addStatusBarPadding21v(getActivity(), view);
    if (dialog.getType() == ContextMenuCardDialog.CardDialogType.MAPILLARY) {
        view.findViewById(R.id.dialog_layout).setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.mapillary_action_bar));
    }
    contentLayout = (LinearLayout) view.findViewById(R.id.content);
    contentView = dialog.getContentView();
    if (contentView != null) {
        contentLayout.addView(contentView);
    }
    view.findViewById(R.id.close_button).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    if (!Algorithms.isEmpty(dialog.getTitle())) {
        ((TextView) view.findViewById(R.id.title)).setText(dialog.getTitle());
    }
    if (!Algorithms.isEmpty(dialog.getDescription())) {
        ((TextView) view.findViewById(R.id.description)).setText(dialog.getDescription());
    }
    AppCompatImageView moreButton = (AppCompatImageView) view.findViewById(R.id.more_button);
    if (dialog.haveMenuItems()) {
        moreButton.setVisibility(View.VISIBLE);
        moreButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                final PopupMenu optionsMenu = new PopupMenu(getContext(), v);
                DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
                dialog.createMenuItems(optionsMenu.getMenu());
                optionsMenu.show();
            }
        });
    } else {
        moreButton.setVisibility(View.GONE);
    }
    return view;
}
Also used : TextView(android.widget.TextView) AppCompatImageView(android.support.v7.widget.AppCompatImageView) TextView(android.widget.TextView) View(android.view.View) WebView(android.webkit.WebView) AppCompatImageView(android.support.v7.widget.AppCompatImageView) PopupMenu(android.support.v7.widget.PopupMenu) Nullable(android.support.annotation.Nullable)

Example 64 with PopupMenu

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

the class TrackDetailsMenu method updateView.

private void updateView(final View parentView) {
    GPXTrackAnalysis analysis = gpxItem.analysis;
    if (analysis == null || gpxItem.chartTypes == null) {
        parentView.setVisibility(View.GONE);
        if (analysis != null && analysis.isBoundsCalculated()) {
            mapActivity.getMapView().fitRectToMap(analysis.left, analysis.right, analysis.top, analysis.bottom, 0, 0, 0);
        }
        return;
    }
    final LineChart chart = (LineChart) parentView.findViewById(R.id.chart);
    chart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {

        @Override
        public void onValueSelected(Entry e, Highlight h) {
            refreshChart(chart, false);
        }

        @Override
        public void onNothingSelected() {
        }
    });
    chart.setOnChartGestureListener(new OnChartGestureListener() {

        boolean hasTranslated = false;

        float highlightDrawX = -1;

        @Override
        public void onChartGestureStart(MotionEvent me, ChartGesture lastPerformedGesture) {
            hasTranslated = false;
            if (chart.getHighlighted() != null && chart.getHighlighted().length > 0) {
                highlightDrawX = chart.getHighlighted()[0].getDrawX();
            } else {
                highlightDrawX = -1;
            }
        }

        @Override
        public void onChartGestureEnd(MotionEvent me, ChartGesture lastPerformedGesture) {
            if ((lastPerformedGesture == ChartGesture.DRAG && hasTranslated) || lastPerformedGesture == ChartGesture.X_ZOOM || lastPerformedGesture == ChartGesture.Y_ZOOM || lastPerformedGesture == ChartGesture.PINCH_ZOOM || lastPerformedGesture == ChartGesture.DOUBLE_TAP || lastPerformedGesture == ChartGesture.ROTATE) {
                gpxItem.chartMatrix = new Matrix(chart.getViewPortHandler().getMatrixTouch());
                refreshChart(chart, true);
            }
        }

        @Override
        public void onChartLongPressed(MotionEvent me) {
        }

        @Override
        public void onChartDoubleTapped(MotionEvent me) {
        }

        @Override
        public void onChartSingleTapped(MotionEvent me) {
        }

        @Override
        public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) {
        }

        @Override
        public void onChartScale(MotionEvent me, float scaleX, float scaleY) {
        }

        @Override
        public void onChartTranslate(MotionEvent me, float dX, float dY) {
            hasTranslated = true;
            if (highlightDrawX != -1) {
                Highlight h = chart.getHighlightByTouchPoint(highlightDrawX, 0f);
                if (h != null) {
                    chart.highlightValue(h);
                    refreshChart(chart, false);
                }
            }
        }
    });
    final OsmandApplication app = mapActivity.getMyApplication();
    final IconsCache ic = app.getIconsCache();
    GpxUiHelper.setupGPXChart(app, chart, 4);
    List<ILineDataSet> dataSets = new ArrayList<>();
    if (gpxItem.chartTypes != null && gpxItem.chartTypes.length > 0) {
        for (int i = 0; i < gpxItem.chartTypes.length; i++) {
            OrderedLineDataSet dataSet = null;
            switch(gpxItem.chartTypes[i]) {
                case ALTITUDE:
                    dataSet = GpxUiHelper.createGPXElevationDataSet(app, chart, analysis, gpxItem.chartAxisType, false, true);
                    break;
                case SPEED:
                    dataSet = GpxUiHelper.createGPXSpeedDataSet(app, chart, analysis, gpxItem.chartAxisType, gpxItem.chartTypes.length > 1, true);
                    break;
                case SLOPE:
                    dataSet = GpxUiHelper.createGPXSlopeDataSet(app, chart, analysis, gpxItem.chartAxisType, null, gpxItem.chartTypes.length > 1, true);
                    break;
            }
            if (dataSet != null) {
                dataSets.add(dataSet);
            }
        }
    }
    Collections.sort(dataSets, new Comparator<ILineDataSet>() {

        @Override
        public int compare(ILineDataSet ds1, ILineDataSet ds2) {
            OrderedLineDataSet dataSet1 = (OrderedLineDataSet) ds1;
            OrderedLineDataSet dataSet2 = (OrderedLineDataSet) ds2;
            return dataSet1.getPriority() > dataSet2.getPriority() ? -1 : (dataSet1.getPriority() == dataSet2.getPriority() ? 0 : 1);
        }
    });
    chart.setData(new LineData(dataSets));
    updateChart(chart);
    View yAxis = parentView.findViewById(R.id.y_axis);
    ImageView yAxisIcon = (ImageView) parentView.findViewById(R.id.y_axis_icon);
    TextView yAxisTitle = (TextView) parentView.findViewById(R.id.y_axis_title);
    View yAxisArrow = parentView.findViewById(R.id.y_axis_arrow);
    final List<GPXDataSetType[]> availableTypes = new ArrayList<>();
    boolean hasSlopeChart = false;
    if (analysis.hasElevationData) {
        availableTypes.add(new GPXDataSetType[] { GPXDataSetType.ALTITUDE });
        if (gpxItem.chartAxisType != GPXDataSetAxisType.TIME) {
            availableTypes.add(new GPXDataSetType[] { GPXDataSetType.SLOPE });
        }
    }
    if (analysis.hasSpeedData) {
        availableTypes.add(new GPXDataSetType[] { GPXDataSetType.SPEED });
    }
    if (analysis.hasElevationData && gpxItem.chartAxisType != GPXDataSetAxisType.TIME) {
        availableTypes.add(new GPXDataSetType[] { GPXDataSetType.ALTITUDE, GPXDataSetType.SLOPE });
    }
    if (analysis.hasElevationData && analysis.hasSpeedData) {
        availableTypes.add(new GPXDataSetType[] { GPXDataSetType.ALTITUDE, GPXDataSetType.SPEED });
    }
    for (GPXDataSetType t : gpxItem.chartTypes) {
        if (t == GPXDataSetType.SLOPE) {
            hasSlopeChart = true;
            break;
        }
    }
    yAxisIcon.setImageDrawable(GPXDataSetType.getImageDrawable(app, gpxItem.chartTypes));
    yAxisTitle.setText(GPXDataSetType.getName(app, gpxItem.chartTypes));
    if (availableTypes.size() > 0) {
        yAxis.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                final PopupMenu optionsMenu = new PopupMenu(mapActivity, v);
                DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
                for (final GPXDataSetType[] types : availableTypes) {
                    MenuItem menuItem = optionsMenu.getMenu().add(GPXDataSetType.getName(app, types)).setIcon(GPXDataSetType.getImageDrawable(app, types));
                    menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem mItem) {
                            gpxItem.chartTypes = types;
                            update();
                            return true;
                        }
                    });
                }
                optionsMenu.show();
            }
        });
        yAxisArrow.setVisibility(View.VISIBLE);
    } else {
        yAxis.setOnClickListener(null);
        yAxis.setBackgroundResource(0);
        yAxisArrow.setVisibility(View.GONE);
    }
    View xAxis = parentView.findViewById(R.id.x_axis);
    ImageView xAxisIcon = (ImageView) parentView.findViewById(R.id.x_axis_icon);
    TextView xAxisTitle = (TextView) parentView.findViewById(R.id.x_axis_title);
    View xAxisArrow = parentView.findViewById(R.id.x_axis_arrow);
    if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME) {
        xAxisIcon.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_time));
        xAxisTitle.setText(app.getString(R.string.shared_string_time));
    } else {
        xAxisIcon.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_marker_dark));
        xAxisTitle.setText(app.getString(R.string.distance));
    }
    if (analysis.isTimeSpecified() && !hasSlopeChart) {
        xAxis.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                final PopupMenu optionsMenu = new PopupMenu(mapActivity, v);
                DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
                final GPXDataSetAxisType type;
                if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME) {
                    type = GPXDataSetAxisType.DISTANCE;
                } else {
                    type = GPXDataSetAxisType.TIME;
                }
                MenuItem menuItem = optionsMenu.getMenu().add(type.getStringId()).setIcon(type.getImageDrawable(app));
                menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem mItem) {
                        gpxItem.chartAxisType = type;
                        gpxItem.chartHighlightPos = -1;
                        gpxItem.chartMatrix = null;
                        update();
                        return true;
                    }
                });
                optionsMenu.show();
            }
        });
        xAxisArrow.setVisibility(View.VISIBLE);
    } else {
        xAxis.setOnClickListener(null);
        xAxis.setBackgroundResource(0);
        xAxisArrow.setVisibility(View.GONE);
    }
    refreshChart(chart, true);
}
Also used : OnChartValueSelectedListener(com.github.mikephil.charting.listener.OnChartValueSelectedListener) Highlight(com.github.mikephil.charting.highlight.Highlight) OsmandApplication(net.osmand.plus.OsmandApplication) ArrayList(java.util.ArrayList) ChartGesture(com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture) Entry(com.github.mikephil.charting.data.Entry) Matrix(android.graphics.Matrix) ILineDataSet(com.github.mikephil.charting.interfaces.datasets.ILineDataSet) GPXDataSetType(net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType) TextView(android.widget.TextView) ImageView(android.widget.ImageView) OnChartGestureListener(com.github.mikephil.charting.listener.OnChartGestureListener) GPXTrackAnalysis(net.osmand.plus.GPXUtilities.GPXTrackAnalysis) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) MotionEvent(android.view.MotionEvent) LineData(com.github.mikephil.charting.data.LineData) GPXDataSetAxisType(net.osmand.plus.helpers.GpxUiHelper.GPXDataSetAxisType) OrderedLineDataSet(net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet) IconsCache(net.osmand.plus.IconsCache) LineChart(com.github.mikephil.charting.charts.LineChart) PopupMenu(android.support.v7.widget.PopupMenu)

Example 65 with PopupMenu

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

the class RoutePreferencesMenu method showOptionsMenu.

private void showOptionsMenu(final TextView gpxSpinner) {
    RouteProvider.GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute();
    final PopupMenu optionsMenu = new PopupMenu(gpxSpinner.getContext(), gpxSpinner);
    MenuItem item = optionsMenu.getMenu().add(mapActivity.getString(R.string.shared_string_none));
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (mapActivity.getRoutingHelper().getCurrentGPXRoute() != null) {
                mapActivity.getRoutingHelper().setGpxParams(null);
                settings.FOLLOW_THE_GPX_ROUTE.set(null);
                mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();
            }
            updateParameters();
            return true;
        }
    });
    item = optionsMenu.getMenu().add(mapActivity.getString(R.string.select_gpx));
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            openGPXFileSelection(gpxSpinner);
            return true;
        }
    });
    if (rp != null) {
        item = optionsMenu.getMenu().add(new File(rp.getFile().path).getName());
        item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                // nothing to change
                return true;
            }
        });
    }
    optionsMenu.show();
}
Also used : RouteProvider(net.osmand.plus.routing.RouteProvider) MenuItem(android.view.MenuItem) ContextMenuItem(net.osmand.plus.ContextMenuItem) File(java.io.File) PopupMenu(android.support.v7.widget.PopupMenu)

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