Search in sources :

Example 16 with ContextMenuItem

use of net.osmand.plus.ContextMenuItem in project Osmand by osmandapp.

the class GpxUiHelper method setDescripionInDialog.

private static void setDescripionInDialog(final ArrayAdapter<?> adapter, final ContextMenuAdapter cmAdapter, Activity activity, final File dir, String filename, final int position) {
    final Application app = activity.getApplication();
    final File f = new File(dir, filename);
    loadGPXFileInDifferentThread(activity, new CallbackWithObject<GPXUtilities.GPXFile[]>() {

        @Override
        public boolean processResult(GPXFile[] result) {
            ContextMenuItem item = cmAdapter.getItem(position);
            item.setTitle(item.getTitle() + "\n" + getDescription((OsmandApplication) app, result[0], f, false));
            adapter.notifyDataSetInvalidated();
            return true;
        }
    }, dir, null, filename);
}
Also used : ContextMenuItem(net.osmand.plus.ContextMenuItem) OsmandApplication(net.osmand.plus.OsmandApplication) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) OsmandApplication(net.osmand.plus.OsmandApplication) Application(android.app.Application) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) File(java.io.File) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) GPXUtilities(net.osmand.plus.GPXUtilities)

Example 17 with ContextMenuItem

use of net.osmand.plus.ContextMenuItem in project Osmand by osmandapp.

the class GpxUiHelper method createSingleChoiceDialog.

private static AlertDialog createSingleChoiceDialog(final Activity activity, final boolean showCurrentGpx, final CallbackWithObject<GPXFile[]> callbackWithObject, final List<GPXInfo> list, final ContextMenuAdapter adapter) {
    final OsmandApplication app = (OsmandApplication) activity.getApplication();
    final IconsCache iconsCache = app.getIconsCache();
    final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    final int layout = R.layout.list_menu_item_native_singlechoice;
    final ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(activity, layout, R.id.text1, adapter.getItemNames()) {

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            // User super class to create the View
            View v = convertView;
            if (v == null) {
                v = activity.getLayoutInflater().inflate(layout, null);
            }
            final ContextMenuItem item = adapter.getItem(position);
            TextView tv = (TextView) v.findViewById(R.id.text1);
            Drawable icon;
            if (showCurrentGpx && position == 0) {
                icon = null;
            } else {
                icon = iconsCache.getThemedIcon(item.getIcon());
            }
            tv.setCompoundDrawablePadding(AndroidUtils.dpToPx(activity, 10f));
            tv.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
            tv.setText(item.getTitle());
            tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
            return v;
        }
    };
    int selectedIndex = 0;
    String prevSelectedGpx = app.getSettings().LAST_SELECTED_GPX_TRACK_FOR_NEW_POINT.get();
    if (prevSelectedGpx != null) {
        selectedIndex = list.indexOf(prevSelectedGpx);
    }
    if (selectedIndex == -1) {
        selectedIndex = 0;
    }
    final int[] selectedPosition = { selectedIndex };
    builder.setSingleChoiceItems(listAdapter, selectedIndex, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int position) {
            selectedPosition[0] = position;
        }
    });
    builder.setTitle(R.string.select_gpx).setPositiveButton(R.string.shared_string_ok, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            int position = selectedPosition[0];
            if (position != -1) {
                if (showCurrentGpx && position == 0) {
                    callbackWithObject.processResult(null);
                    app.getSettings().LAST_SELECTED_GPX_TRACK_FOR_NEW_POINT.set(null);
                } else {
                    String fileName = list.get(position).getFileName();
                    app.getSettings().LAST_SELECTED_GPX_TRACK_FOR_NEW_POINT.set(fileName);
                    SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByName(fileName);
                    if (selectedGpxFile != null) {
                        callbackWithObject.processResult(new GPXFile[] { selectedGpxFile.getGpxFile() });
                    } else {
                        loadGPXFileInDifferentThread(activity, callbackWithObject, dir, null, fileName);
                    }
                }
            }
        }
    }).setNegativeButton(R.string.shared_string_cancel, null);
    final AlertDialog dlg = builder.create();
    dlg.setCanceledOnTouchOutside(false);
    dlg.show();
    try {
        dlg.getListView().setFastScrollEnabled(true);
    } catch (Exception e) {
    // java.lang.ClassCastException: com.android.internal.widget.RoundCornerListAdapter
    // Unknown reason but on some devices fail
    }
    return dlg;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) ContextMenuItem(net.osmand.plus.ContextMenuItem) DialogInterface(android.content.DialogInterface) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) SpannableString(android.text.SpannableString) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) MarkerView(com.github.mikephil.charting.components.MarkerView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) OnClickListener(android.content.DialogInterface.OnClickListener) TextView(android.widget.TextView) IconsCache(net.osmand.plus.IconsCache) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) File(java.io.File) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) ArrayAdapter(android.widget.ArrayAdapter)

Example 18 with ContextMenuItem

use of net.osmand.plus.ContextMenuItem in project Osmand by osmandapp.

the class LocalIndexesFragment method showContextMenu.

private void showContextMenu(final LocalIndexInfo info) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    final ContextMenuAdapter adapter = new ContextMenuAdapter();
    basicFileOperation(info, adapter);
    OsmandPlugin.onContextMenuActivity(getActivity(), null, info, adapter);
    String[] values = adapter.getItemNames();
    builder.setItems(values, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            ContextMenuItem item = adapter.getItem(which);
            if (item.getItemClickListener() != null) {
                item.getItemClickListener().onContextMenuClick(null, item.getTitleId(), which, false, null);
            }
        }
    });
    builder.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ContextMenuItem(net.osmand.plus.ContextMenuItem) DialogInterface(android.content.DialogInterface)

Example 19 with ContextMenuItem

use of net.osmand.plus.ContextMenuItem in project Osmand by osmandapp.

the class AdditionalActionsBottomSheetDialogFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Activity activity = getActivity();
    nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
    portrait = AndroidUiHelper.isOrientationPortrait(activity);
    final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
    availableScreenH = AndroidUtils.getScreenHeight(activity) - AndroidUtils.getStatusBarHeight(activity);
    if (portrait) {
        availableScreenH -= AndroidUtils.getNavBarHeight(activity);
    }
    View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_context_menu_actions_bottom_sheet_dialog, null);
    scrollView = mainView.findViewById(R.id.bottom_sheet_scroll_view);
    cancelRowBgView = mainView.findViewById(R.id.cancel_row_background);
    updateBackground(false);
    cancelRowBgView.setBackgroundResource(getCancelRowBgResId());
    mainView.findViewById(R.id.divider).setBackgroundResource(nightMode ? R.color.route_info_bottom_view_bg_dark : R.color.route_info_divider_light);
    View.OnClickListener dismissOnClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            dismiss();
        }
    };
    mainView.findViewById(R.id.cancel_row).setOnClickListener(dismissOnClickListener);
    mainView.findViewById(R.id.scroll_view_container).setOnClickListener(dismissOnClickListener);
    View.OnClickListener onClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (listener != null) {
                listener.onItemClick((int) view.getTag());
            }
            dismiss();
        }
    };
    LinearLayout itemsLinearLayout = (LinearLayout) mainView.findViewById(R.id.context_menu_items_container);
    LinearLayout row = (LinearLayout) View.inflate(getContext(), R.layout.grid_menu_row, null);
    int itemsAdded = 0;
    for (int i = 0; i < adapter.length(); i++) {
        ContextMenuItem item = adapter.getItem(i);
        View menuItem = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.grid_menu_item, null);
        if (item.getIcon() != ContextMenuItem.INVALID_ID) {
            ((ImageView) menuItem.findViewById(R.id.icon)).setImageDrawable(getContentIcon(item.getIcon()));
        }
        ((TextView) menuItem.findViewById(R.id.title)).setText(item.getTitle());
        if (item.isClickable()) {
            menuItem.setTag(i);
            menuItem.setOnClickListener(onClickListener);
        } else {
            menuItem.setEnabled(false);
            menuItem.setAlpha(.5f);
        }
        ((FrameLayout) row.findViewById(getMenuItemContainerId(itemsAdded))).addView(menuItem);
        itemsAdded++;
        if (itemsAdded == 3 || (i == adapter.length() - 1 && itemsAdded > 0)) {
            itemsLinearLayout.addView(row);
            row = (LinearLayout) View.inflate(getContext(), R.layout.grid_menu_row, null);
            itemsAdded = 0;
        }
    }
    final ExtendedBottomSheetBehavior behavior = ExtendedBottomSheetBehavior.from(scrollView);
    behavior.setBottomSheetCallback(new BottomSheetCallback() {

        @Override
        public void onStateChanged(@NonNull View bottomSheet, int newState) {
            if (newState == ExtendedBottomSheetBehavior.STATE_HIDDEN) {
                dismiss();
            } else {
                updateBackground(newState == ExtendedBottomSheetBehavior.STATE_EXPANDED);
            }
        }

        @Override
        public void onSlide(@NonNull View bottomSheet, float slideOffset) {
        }
    });
    if (portrait) {
        behavior.setPeekHeight(getResources().getDimensionPixelSize(R.dimen.bottom_sheet_menu_peek_height));
    } else {
        getDialog().setOnShowListener(new DialogInterface.OnShowListener() {

            @Override
            public void onShow(DialogInterface dialog) {
                behavior.setState(ExtendedBottomSheetBehavior.STATE_EXPANDED);
            }
        });
    }
    return mainView;
}
Also used : ExtendedBottomSheetBehavior(net.osmand.plus.widgets.tools.ExtendedBottomSheetBehavior) ContextMenuItem(net.osmand.plus.ContextMenuItem) DialogInterface(android.content.DialogInterface) Activity(android.app.Activity) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) ContextThemeWrapper(android.view.ContextThemeWrapper) FrameLayout(android.widget.FrameLayout) TextView(android.widget.TextView) ImageView(android.widget.ImageView) BottomSheetCallback(net.osmand.plus.widgets.tools.ExtendedBottomSheetBehavior.BottomSheetCallback) LinearLayout(android.widget.LinearLayout) Nullable(android.support.annotation.Nullable)

Example 20 with ContextMenuItem

use of net.osmand.plus.ContextMenuItem in project Osmand by osmandapp.

the class MapillaryPlugin method registerLayerContextMenuActions.

@Override
public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) {
    ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.OnRowItemClick() {

        @Override
        public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
            if (itemId == R.string.mapillary) {
                mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.MAPILLARY, AndroidUtils.getCenterViewCoordinates(view));
                return false;
            }
            return true;
        }

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
            final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
            if (itemId == R.string.mapillary) {
                OsmandMapTileView mapView = mapActivity.getMapView();
                MapActivityLayers mapLayers = mapActivity.getMapLayers();
                settings.SHOW_MAPILLARY.set(!settings.SHOW_MAPILLARY.get());
                updateMapLayers(mapView, mapLayers, false);
                ContextMenuItem item = adapter.getItem(pos);
                if (item != null) {
                    item.setSelected(settings.SHOW_MAPILLARY.get());
                    item.setColorRes(settings.SHOW_MAPILLARY.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
                    adapter.notifyDataSetChanged();
                }
            }
            return false;
        }
    };
    if (rasterLayer.getMap() == null) {
        settings.SHOW_MAPILLARY.set(false);
    }
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.mapillary, mapActivity).setSelected(settings.SHOW_MAPILLARY.get()).setColor(settings.SHOW_MAPILLARY.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_mapillary).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(listener).setPosition(11).createItem());
}
Also used : ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) MapActivityLayers(net.osmand.plus.activities.MapActivityLayers) ContextMenuItem(net.osmand.plus.ContextMenuItem) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) View(android.view.View) ArrayAdapter(android.widget.ArrayAdapter) OsmandSettings(net.osmand.plus.OsmandSettings)

Aggregations

ContextMenuItem (net.osmand.plus.ContextMenuItem)37 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)27 ArrayAdapter (android.widget.ArrayAdapter)23 View (android.view.View)19 DialogInterface (android.content.DialogInterface)16 ItemClickListener (net.osmand.plus.ContextMenuAdapter.ItemClickListener)13 AlertDialog (android.support.v7.app.AlertDialog)12 TextView (android.widget.TextView)11 OsmandApplication (net.osmand.plus.OsmandApplication)11 OsmandSettings (net.osmand.plus.OsmandSettings)11 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)11 AdapterView (android.widget.AdapterView)10 ImageView (android.widget.ImageView)9 ArrayList (java.util.ArrayList)8 ViewGroup (android.view.ViewGroup)6 ListView (android.widget.ListView)6 RenderingRuleProperty (net.osmand.render.RenderingRuleProperty)6 Intent (android.content.Intent)5 CompoundButton (android.widget.CompoundButton)5 Drawable (android.graphics.drawable.Drawable)4