Search in sources :

Example 1 with MapMarkersGroup

use of net.osmand.plus.MapMarkersHelper.MapMarkersGroup in project Osmand by osmandapp.

the class EditFavoriteGroupDialogFragment method createMenuItems.

@Override
public void createMenuItems(Bundle savedInstanceState) {
    final OsmandApplication app = getMyApplication();
    FavouritesDbHelper helper = app.getFavorites();
    Bundle args = getArguments();
    if (args != null) {
        String groupName = args.getString(GROUP_NAME_KEY);
        if (groupName != null) {
            group = helper.getGroup(groupName);
        }
    }
    if (group == null) {
        return;
    }
    items.add(new TitleItem(Algorithms.isEmpty(group.name) ? app.getString(R.string.shared_string_favorites) : group.name));
    BaseBottomSheetItem editNameItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_edit_dark)).setTitle(getString(R.string.edit_name)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialog.Builder b = new AlertDialog.Builder(getContext());
            b.setTitle(R.string.favorite_group_name);
            final EditText nameEditText = new EditText(getContext());
            nameEditText.setText(group.name);
            b.setView(nameEditText);
            b.setNegativeButton(R.string.shared_string_cancel, null);
            b.setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String name = nameEditText.getText().toString();
                    boolean nameChanged = !Algorithms.objectEquals(group.name, name);
                    if (nameChanged) {
                        app.getFavorites().editFavouriteGroup(group, name, group.color, group.visible);
                        updateParentFragment();
                    }
                    dismiss();
                }
            });
            b.show();
        }
    }).create();
    items.add(editNameItem);
    final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
    final View changeColorView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.change_fav_color, null);
    ((ImageView) changeColorView.findViewById(R.id.change_color_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_appearance));
    updateColorView((ImageView) changeColorView.findViewById(R.id.colorImage));
    BaseBottomSheetItem changeColorItem = new BaseBottomSheetItem.Builder().setCustomView(changeColorView).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final ListPopupWindow popup = new ListPopupWindow(getActivity());
            popup.setAnchorView(changeColorView);
            popup.setContentWidth(AndroidUtils.dpToPx(app, 200f));
            popup.setModal(true);
            popup.setDropDownGravity(Gravity.END | Gravity.TOP);
            if (AndroidUiHelper.isOrientationPortrait(getActivity())) {
                popup.setVerticalOffset(AndroidUtils.dpToPx(app, 48f));
            } else {
                popup.setVerticalOffset(AndroidUtils.dpToPx(app, -48f));
            }
            popup.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f));
            final FavoriteColorAdapter colorAdapter = new FavoriteColorAdapter(getActivity());
            popup.setAdapter(colorAdapter);
            popup.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    Integer color = colorAdapter.getItem(position);
                    if (color != null) {
                        if (color != group.color) {
                            app.getFavorites().editFavouriteGroup(group, group.name, color, group.visible);
                            updateParentFragment();
                        }
                    }
                    popup.dismiss();
                    dismiss();
                }
            });
            popup.show();
        }
    }).create();
    items.add(changeColorItem);
    BaseBottomSheetItem showOnMapItem = new BottomSheetItemWithCompoundButton.Builder().setChecked(group.visible).setIcon(getContentIcon(R.drawable.ic_map)).setTitle(getString(R.string.shared_string_show_on_map)).setLayoutId(R.layout.bottom_sheet_item_with_switch).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            boolean visible = !group.visible;
            app.getFavorites().editFavouriteGroup(group, group.name, group.color, visible);
            updateParentFragment();
            dismiss();
        }
    }).create();
    items.add(showOnMapItem);
    if (group.points.size() > 0) {
        items.add(new DividerHalfItem(getContext()));
        final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
        final MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(this.group);
        final boolean synced = markersHelper.isGroupSynced(markersGr.getId());
        BaseBottomSheetItem markersGroupItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(synced ? R.drawable.ic_action_delete_dark : R.drawable.ic_action_flag_dark)).setTitle(getString(synced ? R.string.remove_from_map_markers : R.string.shared_string_add_to_map_markers)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (synced) {
                    markersHelper.removeMarkersGroup(markersGr);
                } else {
                    markersHelper.addOrEnableGroup(markersGr);
                }
                dismiss();
                MapActivity.launchMapActivityMoveToTop(getActivity());
            }
        }).create();
        items.add(markersGroupItem);
        BaseBottomSheetItem shareItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_gshare_dark)).setTitle(getString(R.string.shared_string_share)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                FavoritesTreeFragment fragment = getFavoritesTreeFragment();
                if (fragment != null) {
                    fragment.shareFavorites(EditFavoriteGroupDialogFragment.this.group);
                }
                dismiss();
            }
        }).create();
        items.add(shareItem);
    }
}
Also used : BaseBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem) AlertDialog(android.support.v7.app.AlertDialog) SimpleBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) TitleItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem) ListPopupWindow(android.support.v7.widget.ListPopupWindow) DividerHalfItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem) MapMarkersGroup(net.osmand.plus.MapMarkersHelper.MapMarkersGroup) ImageView(android.widget.ImageView) EditText(android.widget.EditText) Bundle(android.os.Bundle) FavouritesDbHelper(net.osmand.plus.FavouritesDbHelper) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ContextThemeWrapper(android.view.ContextThemeWrapper) MapMarkersHelper(net.osmand.plus.MapMarkersHelper) AdapterView(android.widget.AdapterView)

Example 2 with MapMarkersGroup

use of net.osmand.plus.MapMarkersHelper.MapMarkersGroup in project Osmand by osmandapp.

the class MapMarkersDbHelper method readGroup.

private MapMarkersGroup readGroup(SQLiteCursor query) {
    String id = query.getString(0);
    String name = query.getString(1);
    int type = query.getInt(2);
    boolean disabled = query.getInt(3) == 1;
    String categories = query.getString(4);
    MapMarkersGroup res = new MapMarkersGroup(id, name, type);
    res.setDisabled(disabled);
    res.setWptCategories(categories == null ? null : Algorithms.decodeStringSet(categories));
    return res;
}
Also used : MapMarkersGroup(net.osmand.plus.MapMarkersHelper.MapMarkersGroup)

Example 3 with MapMarkersGroup

use of net.osmand.plus.MapMarkersHelper.MapMarkersGroup in project Osmand by osmandapp.

the class MapMarkersGroupsAdapter method getGroupHeaderPosition.

public int getGroupHeaderPosition(String groupId) {
    int pos = -1;
    MapMarkersGroup group = app.getMapMarkersHelper().getMapMarkerGroupById(groupId);
    if (group != null) {
        pos = items.indexOf(group.getGroupHeader());
    }
    return pos;
}
Also used : MapMarkersGroup(net.osmand.plus.MapMarkersHelper.MapMarkersGroup)

Example 4 with MapMarkersGroup

use of net.osmand.plus.MapMarkersHelper.MapMarkersGroup in project Osmand by osmandapp.

the class MapMarkersGroupsAdapter method createDisplayGroups.

private void createDisplayGroups() {
    items = new ArrayList<>();
    MapMarkersHelper helper = app.getMapMarkersHelper();
    helper.updateGroups();
    List<MapMarkersGroup> groups = new ArrayList<>(helper.getMapMarkersGroups());
    groups.addAll(helper.getGroupsForDisplayedGpx());
    for (int i = 0; i < groups.size(); i++) {
        MapMarkersGroup group = groups.get(i);
        if (!group.isVisible()) {
            continue;
        }
        String markerGroupName = group.getName();
        if (markerGroupName == null) {
            int previousDateHeader = -1;
            int monthsDisplayed = 0;
            Calendar currentDateCalendar = Calendar.getInstance();
            currentDateCalendar.setTimeInMillis(System.currentTimeMillis());
            int currentDay = currentDateCalendar.get(Calendar.DAY_OF_YEAR);
            int currentMonth = currentDateCalendar.get(Calendar.MONTH);
            int currentYear = currentDateCalendar.get(Calendar.YEAR);
            Calendar markerCalendar = Calendar.getInstance();
            List<MapMarker> groupMarkers = group.getActiveMarkers();
            for (int j = 0; j < groupMarkers.size(); j++) {
                MapMarker marker = groupMarkers.get(j);
                markerCalendar.setTimeInMillis(marker.creationDate);
                int markerDay = markerCalendar.get(Calendar.DAY_OF_YEAR);
                int markerMonth = markerCalendar.get(Calendar.MONTH);
                int markerYear = markerCalendar.get(Calendar.YEAR);
                if (markerYear == currentYear) {
                    if (markerDay == currentDay && previousDateHeader != TODAY_HEADER) {
                        items.add(TODAY_HEADER);
                        previousDateHeader = TODAY_HEADER;
                    } else if (markerDay == currentDay - 1 && previousDateHeader != YESTERDAY_HEADER) {
                        items.add(YESTERDAY_HEADER);
                        previousDateHeader = YESTERDAY_HEADER;
                    } else if (currentDay - markerDay >= 2 && currentDay - markerDay <= 8 && previousDateHeader != LAST_SEVEN_DAYS_HEADER) {
                        items.add(LAST_SEVEN_DAYS_HEADER);
                        previousDateHeader = LAST_SEVEN_DAYS_HEADER;
                    } else if (currentDay - markerDay > 8 && monthsDisplayed < 3 && previousDateHeader != markerMonth) {
                        items.add(markerMonth);
                        previousDateHeader = markerMonth;
                        monthsDisplayed += 1;
                    } else if (currentMonth - markerMonth >= 4 && previousDateHeader != THIS_YEAR_HEADER) {
                        items.add(THIS_YEAR_HEADER);
                        previousDateHeader = THIS_YEAR_HEADER;
                    }
                } else if (previousDateHeader != markerYear) {
                    items.add(markerYear);
                    previousDateHeader = markerYear;
                }
                items.add(marker);
            }
        } else {
            GroupHeader header = group.getGroupHeader();
            items.add(header);
            populateAdapterWithGroupMarkers(group, getItemCount());
        }
    }
}
Also used : MapMarkersHelper(net.osmand.plus.MapMarkersHelper) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) Calendar(java.util.Calendar) GroupHeader(net.osmand.plus.MapMarkersHelper.GroupHeader) ArrayList(java.util.ArrayList) MapMarkersGroup(net.osmand.plus.MapMarkersHelper.MapMarkersGroup)

Example 5 with MapMarkersGroup

use of net.osmand.plus.MapMarkersHelper.MapMarkersGroup in project Osmand by osmandapp.

the class TrackPointFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();
    getTrackActivity().getClearToolbar(false);
    MenuItem mi = createMenuItem(menu, SEARCH_ID, R.string.search_poi_filter, R.drawable.ic_action_search_dark, R.drawable.ic_action_search_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    searchView = new SearchView(getActivity());
    FavoritesActivity.updateSearchView(getActivity(), searchView);
    MenuItemCompat.setActionView(mi, searchView);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            adapter.getFilter().filter(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            adapter.getFilter().filter(newText);
            return true;
        }
    });
    MenuItemCompat.setOnActionExpandListener(mi, new MenuItemCompat.OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            adapter.setFilterResults(null);
            adapter.synchronizeGroups(filterGroups());
            adapter.notifyDataSetChanged();
            // Needed to hide intermediate progress bar after closing action mode
            new Handler().postDelayed(new Runnable() {

                public void run() {
                    hideProgressBar();
                }
            }, 100);
            return true;
        }
    });
    if (!MenuItemCompat.isActionViewExpanded(mi)) {
        final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
        final MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(getGpxDataItem().getFile());
        final boolean synced = markersHelper.isGroupSynced(markersGr.getId());
        createMenuItem(menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark, R.drawable.ic_action_gshare_dark, MenuItemCompat.SHOW_AS_ACTION_NEVER);
        createMenuItem(menu, SELECT_MAP_MARKERS_ID, synced ? R.string.remove_from_map_markers : R.string.shared_string_add_to_map_markers, R.drawable.ic_action_flag_dark, R.drawable.ic_action_flag_dark, MenuItemCompat.SHOW_AS_ACTION_NEVER);
        createMenuItem(menu, SELECT_FAVORITES_ID, R.string.shared_string_add_to_favorites, R.drawable.ic_action_fav_dark, R.drawable.ic_action_fav_dark, MenuItemCompat.SHOW_AS_ACTION_NEVER);
        createMenuItem(menu, DELETE_ID, R.string.shared_string_delete, R.drawable.ic_action_delete_dark, R.drawable.ic_action_delete_dark, MenuItemCompat.SHOW_AS_ACTION_NEVER);
    }
    this.optionsMenu = menu;
}
Also used : MenuItemCompat(android.support.v4.view.MenuItemCompat) SearchView(android.support.v7.widget.SearchView) MapMarkersHelper(net.osmand.plus.MapMarkersHelper) Handler(android.os.Handler) MenuItem(android.view.MenuItem) MapMarkersGroup(net.osmand.plus.MapMarkersHelper.MapMarkersGroup)

Aggregations

MapMarkersGroup (net.osmand.plus.MapMarkersHelper.MapMarkersGroup)10 MapMarkersHelper (net.osmand.plus.MapMarkersHelper)7 View (android.view.View)3 ImageView (android.widget.ImageView)3 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)3 Bundle (android.os.Bundle)2 SearchView (android.support.v7.widget.SearchView)2 TextView (android.widget.TextView)2 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2 LinkedHashMap (java.util.LinkedHashMap)2 FavouritePoint (net.osmand.data.FavouritePoint)2 LatLon (net.osmand.data.LatLon)2 SelectedGpxFile (net.osmand.plus.GpxSelectionHelper.SelectedGpxFile)2 GroupHeader (net.osmand.plus.MapMarkersHelper.GroupHeader)2 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)2 OsmandApplication (net.osmand.plus.OsmandApplication)2 DialogInterface (android.content.DialogInterface)1 Handler (android.os.Handler)1 Snackbar (android.support.design.widget.Snackbar)1