Search in sources :

Example 21 with MapMarker

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

the class CoordinateInputAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final MapMarkerItemViewHolder holder, int position) {
    final MapMarker mapMarker = getItem(position);
    holder.iconDirection.setVisibility(View.VISIBLE);
    holder.icon.setImageDrawable(getColoredIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(mapMarker.colorIndex)));
    holder.mainLayout.setBackgroundColor(getResolvedColor(nightTheme ? R.color.ctx_menu_bg_dark : R.color.bg_color_light));
    holder.title.setTextColor(getResolvedColor(nightTheme ? R.color.ctx_menu_title_color_dark : R.color.color_black));
    holder.divider.setBackgroundColor(getResolvedColor(nightTheme ? R.color.route_info_divider_dark : R.color.dashboard_divider_light));
    holder.optionsBtn.setBackgroundDrawable(getRemoveBtnBgSelector());
    holder.optionsBtn.setImageDrawable(getColoredIcon(R.drawable.ic_action_remove_small, R.color.icon_color));
    holder.iconReorder.setVisibility(View.GONE);
    holder.numberText.setVisibility(View.VISIBLE);
    holder.numberText.setText(String.valueOf(position + 1));
    holder.description.setVisibility(View.GONE);
    holder.optionsBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            int position = holder.getAdapterPosition();
            if (position != RecyclerView.NO_POSITION) {
                mapMarkers.remove(getItem(position));
                notifyDataSetChanged();
            }
        }
    });
    boolean singleItem = getItemCount() == 1;
    boolean fistItem = position == 0;
    boolean lastItem = position == getItemCount() - 1;
    holder.topDivider.setVisibility(fistItem ? View.VISIBLE : View.GONE);
    holder.bottomShadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
    holder.divider.setVisibility((!singleItem && !lastItem) ? View.VISIBLE : View.GONE);
    holder.title.setText(mapMarker.getName(mapActivity));
    DashLocationFragment.updateLocationView(useCenter, location, heading, holder.iconDirection, R.drawable.ic_direction_arrow, holder.distance, new LatLon(mapMarker.getLatitude(), mapMarker.getLongitude()), screenOrientation, mapActivity.getMyApplication(), mapActivity, true);
}
Also used : LatLon(net.osmand.data.LatLon) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 22 with MapMarker

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

the class MapMarkersActiveAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final MapMarkerItemViewHolder holder, final int pos) {
    IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache();
    MapMarker marker = markers.get(pos);
    ImageView markerImageViewToUpdate;
    int drawableResToUpdate;
    int markerColor = MapMarker.getColorId(marker.colorIndex);
    LatLon markerLatLon = new LatLon(marker.getLatitude(), marker.getLongitude());
    final boolean displayedInWidget = pos < mapActivity.getMyApplication().getSettings().DISPLAYED_MARKERS_WIDGETS_COUNT.get();
    if (showDirectionEnabled && displayedInWidget) {
        holder.iconDirection.setVisibility(View.GONE);
        holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_arrow_marker_diretion, markerColor));
        holder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.list_divider_dark : R.color.markers_top_bar_background));
        holder.title.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_white));
        holder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.map_markers_on_map_divider_color));
        holder.optionsBtn.setBackgroundDrawable(mapActivity.getResources().getDrawable(R.drawable.marker_circle_background_on_map_with_inset));
        holder.optionsBtn.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_marker_passed, R.color.color_white));
        holder.iconReorder.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_reorder, R.color.dashboard_subheader_text_dark));
        holder.description.setTextColor(ContextCompat.getColor(mapActivity, R.color.map_markers_on_map_color));
        drawableResToUpdate = R.drawable.ic_arrow_marker_diretion;
        markerImageViewToUpdate = holder.icon;
    } else {
        holder.iconDirection.setVisibility(View.VISIBLE);
        holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, markerColor));
        holder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.bg_color_dark : R.color.bg_color_light));
        holder.title.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.color_white : R.color.color_black));
        holder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.actionbar_dark_color : R.color.dashboard_divider_light));
        holder.optionsBtn.setBackgroundDrawable(mapActivity.getResources().getDrawable(night ? R.drawable.marker_circle_background_dark_with_inset : R.drawable.marker_circle_background_light_with_inset));
        holder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_marker_passed));
        holder.iconReorder.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_reorder));
        holder.description.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.dash_search_icon_dark : R.color.icon_color));
        drawableResToUpdate = R.drawable.ic_direction_arrow;
        markerImageViewToUpdate = holder.iconDirection;
    }
    if (pos == getItemCount() - 1) {
        holder.bottomShadow.setVisibility(View.VISIBLE);
        holder.divider.setVisibility(View.GONE);
    } else {
        holder.bottomShadow.setVisibility(View.GONE);
        holder.divider.setVisibility(View.VISIBLE);
    }
    holder.point.setVisibility(View.VISIBLE);
    holder.iconReorder.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
                listener.onDragStarted(holder);
            }
            return false;
        }
    });
    holder.title.setText(marker.getName(mapActivity));
    String descr;
    if ((descr = marker.groupName) != null) {
        if (descr.equals("")) {
            descr = mapActivity.getString(R.string.shared_string_favorites);
        }
    } else {
        Date date = new Date(marker.creationDate);
        String month = new SimpleDateFormat("MMM", Locale.getDefault()).format(date);
        if (month.length() > 1) {
            month = Character.toUpperCase(month.charAt(0)) + month.substring(1);
        }
        month = month.replaceAll("\\.", "");
        String day = new SimpleDateFormat("d", Locale.getDefault()).format(date);
        descr = month + " " + day;
    }
    if (marker.wptPt != null && !Algorithms.isEmpty(marker.wptPt.category)) {
        descr = marker.wptPt.category + ", " + descr;
    }
    holder.description.setText(descr);
    holder.optionsBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            final int position = holder.getAdapterPosition();
            if (position < 0) {
                return;
            }
            final MapMarker marker = markers.get(position);
            mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory(marker);
            changeMarkers();
            notifyDataSetChanged();
            snackbar = Snackbar.make(holder.itemView, mapActivity.getString(R.string.marker_moved_to_history), Snackbar.LENGTH_LONG).setAction(R.string.shared_string_undo, new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    mapActivity.getMyApplication().getMapMarkersHelper().restoreMarkerFromHistory(marker, position);
                    changeMarkers();
                    notifyDataSetChanged();
                }
            });
            AndroidUtils.setSnackbarTextColor(snackbar, R.color.color_dialog_buttons_dark);
            snackbar.show();
        }
    });
    DashLocationFragment.updateLocationView(useCenter, location, heading, markerImageViewToUpdate, drawableResToUpdate, showDirectionEnabled && displayedInWidget ? markerColor : 0, holder.distance, markerLatLon, screenOrientation, mapActivity.getMyApplication(), mapActivity, true);
}
Also used : MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Date(java.util.Date) MotionEvent(android.view.MotionEvent) LatLon(net.osmand.data.LatLon) IconsCache(net.osmand.plus.IconsCache) ImageView(android.widget.ImageView) SimpleDateFormat(java.text.SimpleDateFormat)

Example 23 with MapMarker

use of net.osmand.plus.MapMarkersHelper.MapMarker 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 24 with MapMarker

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

the class MapMarkersListAdapter method calculateStartAndFinishPos.

private void calculateStartAndFinishPos() {
    OsmandApplication app = mapActivity.getMyApplication();
    boolean startCalculated = false;
    boolean finishCalculated = false;
    boolean firstSelectedMarkerCalculated = false;
    if (app.getMapMarkersHelper().isStartFromMyLocation() && showLocationItem) {
        startPos = 0;
        startCalculated = true;
        if (inRoundTrip && !inDragAndDrop) {
            finishPos = 1;
            finishCalculated = true;
        }
    }
    for (int i = 0; i < items.size(); i++) {
        Object item = items.get(i);
        if (item instanceof MapMarker) {
            MapMarker m = (MapMarker) item;
            if (m.selected) {
                if (!startCalculated) {
                    startPos = i;
                    startCalculated = true;
                }
                firstSelectedMarkerPos = i;
                firstSelectedMarkerCalculated = true;
                break;
            }
        }
    }
    for (int i = items.size() - 1; i >= 0; i--) {
        Object item = items.get(i);
        if (item instanceof MapMarker) {
            MapMarker m = (MapMarker) item;
            if (m.selected) {
                finishPos = i + (inRoundTrip && !inDragAndDrop ? 1 : 0);
                finishCalculated = true;
                break;
            }
        }
    }
    if (!startCalculated) {
        startPos = -1;
    }
    if (!finishCalculated) {
        finishPos = -1;
    }
    if (!firstSelectedMarkerCalculated) {
        firstSelectedMarkerPos = -1;
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker)

Example 25 with MapMarker

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

the class MapMarkersListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final MapMarkerItemViewHolder holder, int pos) {
    OsmandApplication app = mapActivity.getMyApplication();
    boolean night = app.getDaynightHelper().isNightModeForMapControls();
    IconsCache iconsCache = app.getIconsCache();
    boolean locationItem = showLocationItem && pos == 0;
    boolean firstMarkerItem = showLocationItem ? pos == 1 : pos == 0;
    boolean lastMarkerItem = pos == getItemCount() - 1;
    boolean start = pos == startPos;
    final boolean finish = pos == finishPos && startPos != finishPos;
    boolean firstSelectedMarker = pos == firstSelectedMarkerPos;
    boolean roundTripFinishItem = finish && showRoundTripItem;
    boolean useLocation = app.getMapMarkersHelper().isStartFromMyLocation() && showLocationItem;
    MapMarker marker = null;
    Location location = null;
    Object item = getItem(pos);
    if (item instanceof Location) {
        location = (Location) item;
    } else {
        marker = (MapMarker) item;
    }
    holder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.bg_color_dark : R.color.bg_color_light));
    holder.title.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.color_white : R.color.color_black));
    holder.title.setText(location != null ? mapActivity.getString(R.string.shared_string_my_location) : marker.getName(mapActivity));
    holder.iconDirection.setVisibility(View.GONE);
    holder.optionsBtn.setVisibility(roundTripFinishItem ? View.VISIBLE : View.GONE);
    if (roundTripFinishItem) {
        holder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_remove_dark));
        TypedValue outValue = new TypedValue();
        mapActivity.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        holder.optionsBtn.setBackgroundResource(outValue.resourceId);
        holder.optionsBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                listener.onDisableRoundTripClick();
            }
        });
    }
    holder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.actionbar_dark_color : R.color.dashboard_divider_light));
    holder.divider.setVisibility(lastMarkerItem ? View.GONE : View.VISIBLE);
    holder.checkBox.setVisibility(roundTripFinishItem ? View.GONE : View.VISIBLE);
    if (!roundTripFinishItem) {
        holder.checkBox.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                listener.onCheckBoxClick(holder.itemView);
            }
        });
        holder.checkBoxContainer.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                holder.checkBox.performClick();
            }
        });
    }
    holder.bottomShadow.setVisibility(lastMarkerItem ? View.VISIBLE : View.GONE);
    holder.iconReorder.setVisibility(View.VISIBLE);
    holder.iconReorder.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_reorder));
    holder.description.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.dash_search_icon_dark : R.color.icon_color));
    holder.firstDescription.setVisibility((start || finish) ? View.VISIBLE : View.GONE);
    if (start) {
        holder.firstDescription.setText(mapActivity.getString(R.string.shared_string_control_start) + " • ");
    } else if (finish) {
        holder.firstDescription.setText(mapActivity.getString(R.string.shared_string_finish) + " • ");
    }
    if (location != null) {
        holder.icon.setImageDrawable(ContextCompat.getDrawable(mapActivity, R.drawable.map_pedestrian_location));
    } else {
        int res = start ? R.drawable.ic_action_point_start : (finish ? R.drawable.ic_action_point_destination : R.drawable.ic_action_flag_dark);
        holder.icon.setImageDrawable(iconsCache.getIcon(res, MapMarker.getColorId(marker.colorIndex)));
    }
    if (locationItem || roundTripFinishItem) {
        holder.iconReorder.setAlpha(.5f);
        holder.iconReorder.setOnTouchListener(null);
    }
    if (locationItem) {
        holder.topDivider.setVisibility(View.VISIBLE);
        holder.checkBox.setChecked(app.getMapMarkersHelper().isStartFromMyLocation());
        holder.distance.setVisibility(View.GONE);
        holder.description.setText(locDescription.getName());
    } else if (roundTripFinishItem) {
        holder.topDivider.setVisibility(View.GONE);
        holder.description.setText(mapActivity.getString(R.string.round_trip));
    } else {
        holder.topDivider.setVisibility((!showLocationItem && firstMarkerItem) ? View.VISIBLE : View.GONE);
        holder.checkBox.setChecked(marker.selected);
        holder.iconReorder.setAlpha(1f);
        holder.iconReorder.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View view, MotionEvent event) {
                if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
                    inDragAndDrop = true;
                    if (showRoundTripItem) {
                        int roundTripItemPos = finishPos;
                        reloadData();
                        notifyItemRemoved(roundTripItemPos);
                    }
                    listener.onDragStarted(holder);
                }
                return false;
            }
        });
        String descr;
        if ((descr = marker.groupName) != null) {
            if (descr.equals("")) {
                descr = mapActivity.getString(R.string.shared_string_favorites);
            }
        } else {
            Date date = new Date(marker.creationDate);
            String month = new SimpleDateFormat("MMM", Locale.getDefault()).format(date);
            if (month.length() > 1) {
                month = Character.toUpperCase(month.charAt(0)) + month.substring(1);
            }
            String day = new SimpleDateFormat("d", Locale.getDefault()).format(date);
            descr = month + " " + day;
        }
        holder.description.setText(descr);
    }
    boolean showDistance = !roundTripFinishItem && (locationItem ? useLocation : marker != null && marker.selected);
    int visibility = showDistance ? View.VISIBLE : View.GONE;
    holder.distance.setVisibility(visibility);
    holder.point.setVisibility(visibility);
    holder.leftPointSpace.setVisibility(visibility);
    holder.rightPointSpace.setVisibility(visibility);
    if (showDistance) {
        holder.distance.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.color_distance : R.color.color_myloc_distance));
        LatLon first = firstSelectedMarker && useLocation ? new LatLon(myLoc.getLatitude(), myLoc.getLongitude()) : getPreviousSelectedMarkerLatLon(pos);
        float dist = 0;
        if (first != null && marker != null) {
            WptPt pt1 = new WptPt();
            pt1.lat = first.getLatitude();
            pt1.lon = first.getLongitude();
            WptPt pt2 = new WptPt();
            pt2.lat = marker.getLatitude();
            pt2.lon = marker.getLongitude();
            List<WptPt> points = snappedToRoadPoints.get(new Pair<>(pt1, pt2));
            if (points != null) {
                for (int i = 0; i < points.size() - 1; i++) {
                    dist += (float) MapUtils.getDistance(points.get(i).lat, points.get(i).lon, points.get(i + 1).lat, points.get(i + 1).lon);
                }
            } else {
                dist = (float) MapUtils.getDistance(pt1.lat, pt1.lon, pt2.lat, pt2.lon);
            }
        }
        holder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, app));
    }
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Date(java.util.Date) MotionEvent(android.view.MotionEvent) LatLon(net.osmand.data.LatLon) IconsCache(net.osmand.plus.IconsCache) SimpleDateFormat(java.text.SimpleDateFormat) Location(net.osmand.Location) TypedValue(android.util.TypedValue)

Aggregations

MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)38 LatLon (net.osmand.data.LatLon)20 View (android.view.View)13 MapMarkersHelper (net.osmand.plus.MapMarkersHelper)11 RecyclerView (android.support.v7.widget.RecyclerView)10 OsmandApplication (net.osmand.plus.OsmandApplication)10 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)9 ImageView (android.widget.ImageView)8 Location (net.osmand.Location)8 PointDescription (net.osmand.data.PointDescription)8 Paint (android.graphics.Paint)7 Nullable (android.support.annotation.Nullable)6 MapActivity (net.osmand.plus.activities.MapActivity)6 ArrayList (java.util.ArrayList)5 Amenity (net.osmand.data.Amenity)5 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)4 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)4 FavouritePoint (net.osmand.data.FavouritePoint)4 QuadPoint (net.osmand.data.QuadPoint)4 Bitmap (android.graphics.Bitmap)3