Search in sources :

Example 16 with IconsCache

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

the class AvailableGPXFragment method openPopUpMenu.

private void openPopUpMenu(View v, final GpxInfo gpxInfo) {
    IconsCache iconsCache = getMyApplication().getIconsCache();
    final PopupMenu optionsMenu = new PopupMenu(getActivity(), v);
    DirectionsDialogs.setupPopUpMenuIcon(optionsMenu);
    MenuItem item = optionsMenu.getMenu().add(R.string.shared_string_show_on_map).setIcon(iconsCache.getThemedIcon(R.drawable.ic_show_on_map));
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            showGpxOnMap(gpxInfo);
            return true;
        }
    });
    GPXTrackAnalysis analysis;
    if ((analysis = getGpxTrackAnalysis(gpxInfo, app)) != null) {
        if (analysis.totalDistance != 0 && !gpxInfo.currentlyRecordingTrack) {
            item = optionsMenu.getMenu().add(R.string.analyze_on_map).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_info_dark));
            item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    new OpenGpxDetailsTask(gpxInfo).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                    return true;
                }
            });
        }
    }
    item = optionsMenu.getMenu().add(R.string.shared_string_move).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_folder_stroke));
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            moveGpx(gpxInfo);
            return true;
        }
    });
    item = optionsMenu.getMenu().add(R.string.shared_string_rename).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark));
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            LocalIndexesFragment.renameFile(getActivity(), gpxInfo.file, new RenameCallback() {

                @Override
                public void renamedTo(File file) {
                    app.getGpxDatabase().rename(gpxInfo.file, file);
                    asyncLoader = new LoadGpxTask();
                    asyncLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
                }
            });
            return true;
        }
    });
    item = optionsMenu.getMenu().add(R.string.shared_string_share).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_gshare_dark));
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            final Uri fileUri = Uri.fromFile(gpxInfo.file);
            final Intent sendIntent = new Intent(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
            sendIntent.setType("application/gpx+xml");
            startActivity(sendIntent);
            return true;
        }
    });
    final OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class);
    if (osmEditingPlugin != null && osmEditingPlugin.isActive()) {
        item = optionsMenu.getMenu().add(R.string.shared_string_export).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_export));
        item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                osmEditingPlugin.sendGPXFiles(getActivity(), AvailableGPXFragment.this, gpxInfo);
                return true;
            }
        });
    }
    item = optionsMenu.getMenu().add(R.string.shared_string_delete).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_delete_dark));
    item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setMessage(R.string.recording_delete_confirm);
            builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    operationTask = new DeleteGpxTask();
                    operationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, gpxInfo);
                }
            });
            builder.setNegativeButton(R.string.shared_string_cancel, null);
            builder.show();
            return true;
        }
    });
    optionsMenu.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) GPXTrackAnalysis(net.osmand.plus.GPXUtilities.GPXTrackAnalysis) MenuItem(android.view.MenuItem) ContextMenuItem(net.osmand.plus.ContextMenuItem) Intent(android.content.Intent) Uri(android.net.Uri) OsmEditingPlugin(net.osmand.plus.osmedit.OsmEditingPlugin) RenameCallback(net.osmand.plus.download.ui.LocalIndexesFragment.RenameCallback) IconsCache(net.osmand.plus.IconsCache) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File) PopupMenu(android.support.v7.widget.PopupMenu)

Example 17 with IconsCache

use of net.osmand.plus.IconsCache 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)

Example 18 with IconsCache

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

the class MeasurementToolAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final MeasureToolItemVH holder, int pos) {
    IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache();
    holder.iconReorder.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_reorder));
    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.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_measure_point, nightMode ? R.color.ctx_menu_info_text_dark : R.color.icon_color));
    if (nightMode) {
        holder.title.setTextColor(ContextCompat.getColor(mapActivity, R.color.primary_text_dark));
    }
    WptPt pt = points.get(pos);
    String pointTitle = pt.name;
    if (!TextUtils.isEmpty(pointTitle)) {
        holder.title.setText(pointTitle);
    } else {
        if (actionType == ActionType.ADD_ROUTE_POINTS) {
            holder.title.setText(mapActivity.getString(R.string.route_point) + " - " + (pos + 1));
        } else {
            holder.title.setText(mapActivity.getString(R.string.plugin_distance_point) + " - " + (pos + 1));
        }
    }
    String pointDesc = pt.desc;
    if (!TextUtils.isEmpty(pointDesc)) {
        holder.descr.setText(pointDesc);
    } else {
        if (pos < 1) {
            holder.descr.setText(mapActivity.getString(R.string.shared_string_control_start));
        } else {
            float dist = 0;
            for (int i = 1; i <= pos; i++) {
                dist += MapUtils.getDistance(points.get(i - 1).lat, points.get(i - 1).lon, points.get(i).lat, points.get(i).lon);
            }
            holder.descr.setText(OsmAndFormatter.getFormattedDistance(dist, mapActivity.getMyApplication()));
        }
    }
    if (actionType == ActionType.EDIT_SEGMENT) {
        double elevation = pt.ele;
        if (!Double.isNaN(elevation)) {
            String eleStr = (mapActivity.getString(R.string.altitude)).substring(0, 1);
            holder.elevation.setText(eleStr + ": " + OsmAndFormatter.getFormattedAlt(elevation, mapActivity.getMyApplication()));
        } else {
            holder.elevation.setText("");
        }
        float speed = (float) pt.speed;
        if (speed != 0) {
            String speedStr = (mapActivity.getString(R.string.map_widget_speed)).substring(0, 1);
            holder.speed.setText(speedStr + ": " + OsmAndFormatter.getFormattedSpeed(speed, mapActivity.getMyApplication()));
        } else {
            holder.speed.setText("");
        }
    }
    holder.deleteBtn.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_remove_dark, nightMode ? R.color.ctx_menu_info_text_dark : R.color.icon_color));
    holder.deleteBtn.setOnClickListener(new View.OnClickListener() {

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

        @Override
        public void onClick(View view) {
            listener.onItemClick(holder.getAdapterPosition());
        }
    });
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) IconsCache(net.osmand.plus.IconsCache) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) MotionEvent(android.view.MotionEvent)

Example 19 with IconsCache

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

the class MapMarkersGroupsAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
    IconsCache iconsCache = app.getIconsCache();
    if (holder instanceof MapMarkerItemViewHolder) {
        final MapMarkerItemViewHolder itemViewHolder = (MapMarkerItemViewHolder) holder;
        final MapMarker marker = (MapMarker) getItem(position);
        final boolean markerInHistory = marker.history;
        int color;
        if (marker.history) {
            color = R.color.icon_color_light;
        } else {
            color = MapMarker.getColorId(marker.colorIndex);
        }
        ImageView markerImageViewToUpdate;
        int drawableResToUpdate;
        final boolean markerToHighlight = showDirectionMarkers.contains(marker);
        if (showDirectionEnabled && markerToHighlight) {
            itemViewHolder.iconDirection.setVisibility(View.GONE);
            itemViewHolder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_arrow_marker_diretion, color));
            itemViewHolder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.list_divider_dark : R.color.markers_top_bar_background));
            itemViewHolder.title.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_white));
            itemViewHolder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.map_markers_on_map_divider_color));
            itemViewHolder.optionsBtn.setBackgroundDrawable(mapActivity.getResources().getDrawable(R.drawable.marker_circle_background_on_map_with_inset));
            itemViewHolder.optionsBtn.setImageDrawable(iconsCache.getIcon(markerInHistory ? R.drawable.ic_action_reset_to_default_dark : R.drawable.ic_action_marker_passed, R.color.color_white));
            itemViewHolder.description.setTextColor(ContextCompat.getColor(mapActivity, R.color.map_markers_on_map_color));
            drawableResToUpdate = R.drawable.ic_arrow_marker_diretion;
            markerImageViewToUpdate = itemViewHolder.icon;
        } else {
            itemViewHolder.iconDirection.setVisibility(View.VISIBLE);
            itemViewHolder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, color));
            itemViewHolder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.bg_color_dark : R.color.bg_color_light));
            itemViewHolder.title.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.color_white : R.color.color_black));
            itemViewHolder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.actionbar_dark_color : R.color.dashboard_divider_light));
            itemViewHolder.optionsBtn.setBackgroundDrawable(mapActivity.getResources().getDrawable(night ? R.drawable.marker_circle_background_dark_with_inset : R.drawable.marker_circle_background_light_with_inset));
            itemViewHolder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(markerInHistory ? R.drawable.ic_action_reset_to_default_dark : R.drawable.ic_action_marker_passed));
            itemViewHolder.description.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.dash_search_icon_dark : R.color.icon_color));
            drawableResToUpdate = R.drawable.ic_direction_arrow;
            markerImageViewToUpdate = itemViewHolder.iconDirection;
        }
        itemViewHolder.title.setText(marker.getName(app));
        boolean noGroup = marker.groupName == null;
        boolean createdEarly = false;
        if (noGroup && !markerInHistory) {
            Calendar currentDateCalendar = Calendar.getInstance();
            currentDateCalendar.setTimeInMillis(System.currentTimeMillis());
            int currentDay = currentDateCalendar.get(Calendar.DAY_OF_YEAR);
            int currentYear = currentDateCalendar.get(Calendar.YEAR);
            Calendar markerCalendar = Calendar.getInstance();
            markerCalendar.setTimeInMillis(System.currentTimeMillis());
            int markerDay = markerCalendar.get(Calendar.DAY_OF_YEAR);
            int markerYear = markerCalendar.get(Calendar.YEAR);
            createdEarly = currentDay - markerDay >= 2 || currentYear != markerYear;
        }
        if (markerInHistory || createdEarly) {
            itemViewHolder.point.setVisibility(View.VISIBLE);
            itemViewHolder.description.setVisibility(View.VISIBLE);
            Date date;
            if (markerInHistory) {
                date = new Date(marker.visitedDate);
            } else {
                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);
            itemViewHolder.description.setText(app.getString(R.string.passed, month + " " + day));
        } else {
            itemViewHolder.point.setVisibility(View.GONE);
            itemViewHolder.description.setVisibility(View.GONE);
        }
        itemViewHolder.optionsBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                int position = itemViewHolder.getAdapterPosition();
                if (position < 0) {
                    return;
                }
                if (markerInHistory) {
                    app.getMapMarkersHelper().restoreMarkerFromHistory(marker, 0);
                } else {
                    app.getMapMarkersHelper().moveMapMarkerToHistory(marker);
                }
                updateDisplayedData();
                if (!markerInHistory) {
                    snackbar = Snackbar.make(itemViewHolder.itemView, 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, 0);
                            updateDisplayedData();
                        }
                    });
                    AndroidUtils.setSnackbarTextColor(snackbar, R.color.color_dialog_buttons_dark);
                    snackbar.show();
                }
            }
        });
        itemViewHolder.iconReorder.setVisibility(View.GONE);
        itemViewHolder.flagIconLeftSpace.setVisibility(View.VISIBLE);
        boolean lastItem = position == getItemCount() - 1;
        if ((getItemCount() > position + 1 && getItemViewType(position + 1) == HEADER_TYPE) || lastItem) {
            itemViewHolder.divider.setVisibility(View.GONE);
        } else {
            itemViewHolder.divider.setVisibility(View.VISIBLE);
        }
        itemViewHolder.bottomShadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
        LatLon markerLatLon = new LatLon(marker.getLatitude(), marker.getLongitude());
        DashLocationFragment.updateLocationView(useCenter, location, heading, markerImageViewToUpdate, drawableResToUpdate, markerToHighlight ? color : 0, itemViewHolder.distance, markerLatLon, screenOrientation, app, mapActivity, true);
    } else if (holder instanceof MapMarkerHeaderViewHolder) {
        final MapMarkerHeaderViewHolder headerViewHolder = (MapMarkerHeaderViewHolder) holder;
        final Object header = getItem(position);
        String headerString;
        if (header instanceof Integer) {
            headerViewHolder.icon.setVisibility(View.GONE);
            headerViewHolder.iconSpace.setVisibility(View.VISIBLE);
            Integer dateHeader = (Integer) header;
            if (dateHeader == TODAY_HEADER) {
                headerString = app.getString(R.string.today);
            } else if (dateHeader == YESTERDAY_HEADER) {
                headerString = app.getString(R.string.yesterday);
            } else if (dateHeader == LAST_SEVEN_DAYS_HEADER) {
                headerString = app.getString(R.string.last_seven_days);
            } else if (dateHeader == THIS_YEAR_HEADER) {
                headerString = app.getString(R.string.this_year);
            } else if (dateHeader / 100 == 0) {
                headerString = getMonth(dateHeader);
            } else {
                headerString = String.valueOf(dateHeader);
            }
            headerViewHolder.disableGroupSwitch.setVisibility(View.GONE);
        } else if (header instanceof GroupHeader) {
            final GroupHeader groupHeader = (GroupHeader) header;
            final MapMarkersGroup group = groupHeader.getGroup();
            String groupName = group.getName();
            if (groupName.equals("")) {
                groupName = app.getString(R.string.shared_string_favorites);
            } else if (group.getType() == MapMarkersGroup.GPX_TYPE) {
                groupName = groupName.replace(".gpx", "").replace("/", " ").replace("_", " ");
            }
            if (group.isDisabled()) {
                headerString = groupName;
            } else {
                headerString = groupName + " \u2014 " + group.getActiveMarkers().size() + "/" + group.getMarkers().size();
            }
            headerViewHolder.icon.setVisibility(View.VISIBLE);
            headerViewHolder.iconSpace.setVisibility(View.GONE);
            headerViewHolder.icon.setImageDrawable(iconsCache.getIcon(groupHeader.getIconRes(), R.color.divider_color));
            boolean groupIsDisabled = group.isDisabled();
            headerViewHolder.disableGroupSwitch.setVisibility(View.VISIBLE);
            CompoundButton.OnCheckedChangeListener checkedChangeListener = new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton compoundButton, boolean enabled) {
                    final MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
                    final GPXFile[] gpxFile = new GPXFile[1];
                    boolean disabled = !enabled;
                    boolean synced = false;
                    mapMarkersHelper.updateGroupDisabled(group, disabled);
                    if (group.getType() == MapMarkersGroup.GPX_TYPE) {
                        group.setVisibleUntilRestart(disabled);
                        String gpxPath = group.getId();
                        if (disabled) {
                            SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxPath);
                            if (selectedGpxFile != null) {
                                gpxFile[0] = selectedGpxFile.getGpxFile();
                                switchGpxVisibility(gpxFile[0], false);
                            }
                        } else if (mapMarkersHelper.isGroupSynced(group.getId())) {
                            mapMarkersHelper.runSynchronization(group, true);
                            synced = true;
                        }
                    }
                    if (!synced) {
                        if (mapMarkersHelper.isGroupSynced(group.getId())) {
                            mapMarkersHelper.runSynchronization(group);
                        } else {
                            mapMarkersHelper.addOrEnableGroup(group);
                        }
                    }
                    if (disabled) {
                        snackbar = Snackbar.make(holder.itemView, app.getString(R.string.group_will_be_removed_after_restart), Snackbar.LENGTH_LONG).setAction(R.string.shared_string_undo, new View.OnClickListener() {

                            @Override
                            public void onClick(View view) {
                                if (group.getType() == MapMarkersGroup.GPX_TYPE && gpxFile[0] != null) {
                                    switchGpxVisibility(gpxFile[0], true);
                                }
                                mapMarkersHelper.addOrEnableGroup(group);
                            }
                        });
                        AndroidUtils.setSnackbarTextColor(snackbar, R.color.color_dialog_buttons_dark);
                        snackbar.show();
                    }
                }
            };
            headerViewHolder.disableGroupSwitch.setOnCheckedChangeListener(null);
            headerViewHolder.disableGroupSwitch.setChecked(!groupIsDisabled);
            headerViewHolder.disableGroupSwitch.setOnCheckedChangeListener(checkedChangeListener);
        } else {
            throw new IllegalArgumentException("Unsupported header");
        }
        headerViewHolder.title.setText(headerString);
        headerViewHolder.bottomShadow.setVisibility(position == getItemCount() - 1 ? View.VISIBLE : View.GONE);
    } else if (holder instanceof MapMarkersShowHideHistoryViewHolder) {
        final MapMarkersShowHideHistoryViewHolder showHideHistoryViewHolder = (MapMarkersShowHideHistoryViewHolder) holder;
        final ShowHideHistoryButton showHideHistoryButton = (ShowHideHistoryButton) getItem(position);
        final boolean showHistory = showHideHistoryButton.showHistory;
        if (position == getItemCount() - 1) {
            showHideHistoryViewHolder.bottomShadow.setVisibility(View.VISIBLE);
        } else {
            showHideHistoryViewHolder.bottomShadow.setVisibility(View.GONE);
        }
        showHideHistoryViewHolder.title.setText(app.getString(showHistory ? R.string.hide_passed : R.string.show_passed));
        showHideHistoryViewHolder.itemView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                showHideHistoryButton.showHistory = !showHistory;
                createDisplayGroups();
                notifyDataSetChanged();
            }
        });
    }
}
Also used : MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) GroupHeader(net.osmand.plus.MapMarkersHelper.GroupHeader) MapMarkersGroup(net.osmand.plus.MapMarkersHelper.MapMarkersGroup) ImageView(android.widget.ImageView) Calendar(java.util.Calendar) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Date(java.util.Date) LatLon(net.osmand.data.LatLon) MapMarkersHelper(net.osmand.plus.MapMarkersHelper) SelectedGpxFile(net.osmand.plus.GpxSelectionHelper.SelectedGpxFile) ShowHideHistoryButton(net.osmand.plus.MapMarkersHelper.ShowHideHistoryButton) IconsCache(net.osmand.plus.IconsCache) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) SimpleDateFormat(java.text.SimpleDateFormat) CompoundButton(android.widget.CompoundButton)

Example 20 with IconsCache

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

the class MapMarkersHistoryAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    IconsCache iconsCache = app.getIconsCache();
    if (holder instanceof MapMarkerItemViewHolder) {
        final MapMarkerItemViewHolder itemViewHolder = (MapMarkerItemViewHolder) holder;
        final MapMarker marker = (MapMarker) getItem(position);
        itemViewHolder.iconReorder.setVisibility(View.GONE);
        int color = R.color.icon_color_light;
        itemViewHolder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, color));
        itemViewHolder.title.setText(marker.getName(app));
        Date date = new Date(marker.visitedDate);
        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);
        String desc = app.getString(R.string.passed, month + " " + day);
        String markerGroupName = marker.groupName;
        if (markerGroupName != null) {
            if (markerGroupName.equals("")) {
                markerGroupName = app.getString(R.string.shared_string_favorites);
            }
            desc += " • " + markerGroupName;
        }
        itemViewHolder.description.setText(desc);
        itemViewHolder.optionsBtn.setBackgroundDrawable(app.getResources().getDrawable(night ? R.drawable.marker_circle_background_dark_with_inset : R.drawable.marker_circle_background_light_with_inset));
        itemViewHolder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_reset_to_default_dark));
        itemViewHolder.optionsBtn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                int position = itemViewHolder.getAdapterPosition();
                if (position < 0) {
                    return;
                }
                app.getMapMarkersHelper().restoreMarkerFromHistory(marker, 0);
                snackbar = Snackbar.make(itemViewHolder.itemView, app.getString(R.string.marker_moved_to_active), Snackbar.LENGTH_LONG).setAction(R.string.shared_string_undo, new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        app.getMapMarkersHelper().moveMapMarkerToHistory(marker);
                    }
                });
                AndroidUtils.setSnackbarTextColor(snackbar, R.color.color_dialog_buttons_dark);
                snackbar.show();
            }
        });
        itemViewHolder.flagIconLeftSpace.setVisibility(View.VISIBLE);
        itemViewHolder.iconDirection.setVisibility(View.GONE);
        itemViewHolder.leftPointSpace.setVisibility(View.GONE);
        itemViewHolder.rightPointSpace.setVisibility(View.GONE);
        boolean lastItem = position == getItemCount() - 1;
        if ((getItemCount() > position + 1 && getItemViewType(position + 1) == HEADER_TYPE) || lastItem) {
            itemViewHolder.divider.setVisibility(View.GONE);
        } else {
            itemViewHolder.divider.setBackgroundColor(ContextCompat.getColor(app, night ? R.color.actionbar_dark_color : R.color.dashboard_divider_light));
            itemViewHolder.divider.setVisibility(View.VISIBLE);
        }
        itemViewHolder.bottomShadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
    } else if (holder instanceof MapMarkerHeaderViewHolder) {
        final MapMarkerHeaderViewHolder dateViewHolder = (MapMarkerHeaderViewHolder) holder;
        final Integer dateHeader = (Integer) getItem(position);
        String dateString;
        if (dateHeader == TODAY_HEADER) {
            dateString = app.getString(R.string.today);
        } else if (dateHeader == YESTERDAY_HEADER) {
            dateString = app.getString(R.string.yesterday);
        } else if (dateHeader == LAST_SEVEN_DAYS_HEADER) {
            dateString = app.getString(R.string.last_seven_days);
        } else if (dateHeader == THIS_YEAR_HEADER) {
            dateString = app.getString(R.string.this_year);
        } else if (dateHeader / 100 == 0) {
            dateString = getMonth(dateHeader);
        } else {
            dateString = String.valueOf(dateHeader);
        }
        dateViewHolder.disableGroupSwitch.setVisibility(View.GONE);
        dateViewHolder.title.setText(dateString);
    }
}
Also used : MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Date(java.util.Date) IconsCache(net.osmand.plus.IconsCache) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

IconsCache (net.osmand.plus.IconsCache)25 View (android.view.View)16 ImageView (android.widget.ImageView)13 TextView (android.widget.TextView)12 MenuItem (android.view.MenuItem)9 OsmandApplication (net.osmand.plus.OsmandApplication)8 PopupMenu (android.support.v7.widget.PopupMenu)6 RecyclerView (android.support.v7.widget.RecyclerView)5 LatLon (net.osmand.data.LatLon)5 ContextMenuItem (net.osmand.plus.ContextMenuItem)5 MotionEvent (android.view.MotionEvent)4 AdapterView (android.widget.AdapterView)4 ImageButton (android.widget.ImageButton)4 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)4 Intent (android.content.Intent)3 Toolbar (android.support.v7.widget.Toolbar)3 ListView (android.widget.ListView)3 File (java.io.File)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3