Search in sources :

Example 26 with UiUtilities

use of net.osmand.plus.utils.UiUtilities in project Osmand by osmandapp.

the class MapMarkersHistoryAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
    UiUtilities iconsCache = app.getUIUtilities();
    if (holder instanceof MapMarkerItemViewHolder) {
        final MapMarkerItemViewHolder itemViewHolder = (MapMarkerItemViewHolder) holder;
        final MapMarker marker = (MapMarker) getItem(position);
        itemViewHolder.iconReorder.setVisibility(View.GONE);
        int color = ColorUtilities.getDefaultIconColorId(nightMode);
        int actionIconColor = nightMode ? R.color.icon_color_primary_dark : R.color.icon_color_primary_light;
        itemViewHolder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag, color));
        itemViewHolder.title.setText(marker.getName(app));
        String desc = app.getString(R.string.passed, OsmAndFormatter.getFormattedDate(app, marker.visitedDate));
        String markerGroupName = marker.groupName;
        if (markerGroupName != null) {
            if (markerGroupName.isEmpty()) {
                markerGroupName = app.getString(R.string.shared_string_favorites);
            }
            desc += " • " + markerGroupName;
        }
        itemViewHolder.description.setText(desc);
        itemViewHolder.optionsBtn.setBackgroundDrawable(AppCompatResources.getDrawable(app, nightMode ? R.drawable.marker_circle_background_dark_with_inset : R.drawable.marker_circle_background_light_with_inset));
        itemViewHolder.optionsBtn.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_reset_to_default_dark, actionIconColor));
        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);
                    }
                });
                UiUtilities.setupSnackbar(snackbar, nightMode);
                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, nightMode ? R.color.app_bar_color_dark : R.color.divider_color_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);
        dateViewHolder.disableGroupSwitch.setVisibility(View.GONE);
        dateViewHolder.title.setText(HistoryAdapter.getDateForHeader(app, dateHeader));
        dateViewHolder.clearButton.setVisibility(View.VISIBLE);
        dateViewHolder.articleDescription.setVisibility(View.GONE);
        dateViewHolder.clearButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                final List<MapMarker> group = markerGroups.get(dateHeader);
                if (group == null) {
                    return;
                }
                app.getMapMarkersHelper().removeMarkers(group);
                snackbar = Snackbar.make(holder.itemView, app.getString(R.string.n_items_removed), Snackbar.LENGTH_LONG).setAction(R.string.shared_string_undo, new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        for (MapMarker marker : group) {
                            app.getMapMarkersHelper().addMarker(marker);
                        }
                    }
                });
                UiUtilities.setupSnackbar(snackbar, nightMode);
                snackbar.show();
            }
        });
    }
}
Also used : MapMarker(net.osmand.plus.mapmarkers.MapMarker) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) UiUtilities(net.osmand.plus.utils.UiUtilities)

Example 27 with UiUtilities

use of net.osmand.plus.utils.UiUtilities 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();
    UiUtilities iconsCache = app.getUIUtilities();
    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(ColorUtilities.getListBgColor(mapActivity, night));
    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.app_bar_color_dark : R.color.divider_color_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_item_move));
    holder.description.setTextColor(ColorUtilities.getDefaultIconColor(app, night));
    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(AppCompatResources.getDrawable(mapActivity, R.drawable.ic_action_location_color));
    } else {
        int res = start ? R.drawable.ic_action_point_start : (finish ? R.drawable.ic_action_point_destination : R.drawable.ic_action_flag);
        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 (event.getActionMasked() == 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.isEmpty()) {
                descr = mapActivity.getString(R.string.shared_string_favorites);
            }
        } else {
            descr = OsmAndFormatter.getFormattedDate(app, marker.creationDate);
        }
        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.GPXUtilities.WptPt) OsmandApplication(net.osmand.plus.OsmandApplication) MapMarker(net.osmand.plus.mapmarkers.MapMarker) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) MotionEvent(android.view.MotionEvent) UiUtilities(net.osmand.plus.utils.UiUtilities) LatLon(net.osmand.data.LatLon) Location(net.osmand.Location) TypedValue(android.util.TypedValue)

Example 28 with UiUtilities

use of net.osmand.plus.utils.UiUtilities in project Osmand by osmandapp.

the class MapMarkersGroupsAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
    UiUtilities iconsCache = app.getUIUtilities();
    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_default_dark;
        } else {
            color = MapMarker.getColorId(marker.colorIndex);
        }
        ImageView markerImageViewToUpdate;
        int drawableResToUpdate;
        int actionIconColor = night ? R.color.icon_color_primary_dark : R.color.icon_color_primary_light;
        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, night ? R.color.text_color_primary_dark : R.color.color_white));
            itemViewHolder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.map_markers_on_map_divider_color));
            itemViewHolder.optionsBtn.setBackgroundDrawable(AppCompatResources.getDrawable(mapActivity, 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, color));
            itemViewHolder.mainLayout.setBackgroundColor(ColorUtilities.getListBgColor(mapActivity, night));
            itemViewHolder.title.setTextColor(ColorUtilities.getPrimaryTextColor(mapActivity, night));
            itemViewHolder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.app_bar_color_dark : R.color.divider_color_light));
            itemViewHolder.optionsBtn.setBackgroundDrawable(AppCompatResources.getDrawable(mapActivity, night ? R.drawable.marker_circle_background_dark_with_inset : R.drawable.marker_circle_background_light_with_inset));
            itemViewHolder.optionsBtn.setImageDrawable(iconsCache.getIcon(markerInHistory ? R.drawable.ic_action_reset_to_default_dark : R.drawable.ic_action_marker_passed, actionIconColor));
            itemViewHolder.description.setTextColor(ColorUtilities.getDefaultIconColor(mapActivity, night));
            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);
            long date;
            if (markerInHistory) {
                date = marker.visitedDate;
            } else {
                date = marker.creationDate;
            }
            itemViewHolder.description.setText(app.getString(R.string.passed, OsmAndFormatter.getFormattedDate(app, date)));
        } 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();
                        }
                    });
                    UiUtilities.setupSnackbar(snackbar, night);
                    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());
        updateLocationViewCache.arrowResId = drawableResToUpdate;
        updateLocationViewCache.arrowColor = markerToHighlight ? color : 0;
        app.getUIUtilities().updateLocationView(updateLocationViewCache, markerImageViewToUpdate, itemViewHolder.distance, markerLatLon);
    } else if (holder instanceof MapMarkerHeaderViewHolder) {
        final MapMarkerHeaderViewHolder headerViewHolder = (MapMarkerHeaderViewHolder) holder;
        final Object header = getItem(position);
        String headerString;
        if (header instanceof MarkerGroupItem) {
            headerViewHolder.icon.setVisibility(View.GONE);
            headerViewHolder.iconSpace.setVisibility(View.VISIBLE);
            headerString = ((MarkerGroupItem) header).getName(app);
            headerViewHolder.disableGroupSwitch.setVisibility(View.GONE);
            headerViewHolder.articleDescription.setVisibility(View.GONE);
        } else if (header instanceof GroupHeader) {
            final GroupHeader groupHeader = (GroupHeader) header;
            final MapMarkersGroup group = groupHeader.getGroup();
            String groupName = group.getName();
            if (groupName.isEmpty()) {
                groupName = app.getString(R.string.shared_string_favorites);
            } else if (group.getType() == ItineraryType.TRACK) {
                groupName = groupName.replace(IndexConstants.GPX_FILE_EXT, "").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));
            final boolean groupIsDisabled = group.isDisabled();
            headerViewHolder.disableGroupSwitch.setVisibility(View.VISIBLE);
            final TravelArticle article = group.getWikivoyageArticle();
            if (article != null && !groupIsDisabled) {
                headerViewHolder.articleDescription.setVisibility(View.VISIBLE);
                View.OnClickListener openWikiwoyageArticle = new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (mapActivity.getSupportFragmentManager() != null) {
                            WikivoyageArticleDialogFragment.showInstance(app, mapActivity.getSupportFragmentManager(), article.generateIdentifier(), article.getLang());
                        }
                    }
                };
                if (article.getContent().isEmpty()) {
                    headerViewHolder.content.setVisibility(View.GONE);
                } else {
                    headerViewHolder.content.setText(article.getContent());
                    headerViewHolder.content.setOnClickListener(openWikiwoyageArticle);
                }
                headerViewHolder.button.setText(R.string.shared_string_read);
                headerViewHolder.button.setOnClickListener(openWikiwoyageArticle);
            } else {
                headerViewHolder.articleDescription.setVisibility(View.GONE);
            }
            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;
                    if (groupIsDisabled && !group.wasShown() && group.getWptCategories().size() > 1) {
                        group.setWasShown(true);
                        Bundle args = new Bundle();
                        args.putString(SelectWptCategoriesBottomSheetDialogFragment.GPX_FILE_PATH_KEY, group.getGpxPath(app));
                        args.putString(SelectWptCategoriesBottomSheetDialogFragment.ACTIVE_CATEGORIES_KEY, group.getWptCategoriesString());
                        args.putBoolean(SelectWptCategoriesBottomSheetDialogFragment.UPDATE_CATEGORIES_KEY, true);
                        SelectWptCategoriesBottomSheetDialogFragment fragment = new SelectWptCategoriesBottomSheetDialogFragment();
                        fragment.setArguments(args);
                        fragment.setUsedOnMap(false);
                        fragment.show(mapActivity.getSupportFragmentManager(), SelectWptCategoriesBottomSheetDialogFragment.TAG);
                    }
                    mapMarkersHelper.updateGroupDisabled(group, disabled);
                    if (group.getType() == ItineraryType.TRACK) {
                        group.setVisibleUntilRestart(disabled);
                        String gpxPath = group.getGpxPath(app);
                        SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxPath);
                        if (selectedGpxFile != null) {
                            gpxFile[0] = selectedGpxFile.getGpxFile();
                        } else {
                            // TODO IO load in another thread ?
                            gpxFile[0] = GPXUtilities.loadGPXFile(new File(gpxPath));
                        }
                        switchGpxVisibility(gpxFile[0], selectedGpxFile, !disabled);
                    }
                    if (!disabled) {
                        mapMarkersHelper.enableGroup(group);
                    } else {
                        mapMarkersHelper.runSynchronization(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() == ItineraryType.TRACK && gpxFile[0] != null) {
                                    switchGpxVisibility(gpxFile[0], null, true);
                                }
                                mapMarkersHelper.enableGroup(group);
                            }
                        });
                        UiUtilities.setupSnackbar(snackbar, night);
                        snackbar.show();
                    }
                }
            };
            headerViewHolder.disableGroupSwitch.setOnCheckedChangeListener(null);
            headerViewHolder.disableGroupSwitch.setChecked(!groupIsDisabled);
            headerViewHolder.disableGroupSwitch.setOnCheckedChangeListener(checkedChangeListener);
            UiUtilities.setupCompoundButton(headerViewHolder.disableGroupSwitch, night, UiUtilities.CompoundButtonType.GLOBAL);
        } 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();
            }
        });
    } else if (holder instanceof MapMarkerCategoriesViewHolder) {
        final MapMarkerCategoriesViewHolder categoriesViewHolder = (MapMarkerCategoriesViewHolder) holder;
        final Object header = getItem(position);
        if (header instanceof CategoriesSubHeader) {
            final CategoriesSubHeader categoriesSubHeader = (CategoriesSubHeader) header;
            final MapMarkersGroup group = categoriesSubHeader.getGroup();
            View.OnClickListener openChooseCategoriesDialog = new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    if (!group.getWptCategories().isEmpty()) {
                        Bundle args = new Bundle();
                        args.putString(SelectWptCategoriesBottomSheetDialogFragment.GPX_FILE_PATH_KEY, group.getGpxPath(app));
                        args.putBoolean(SelectWptCategoriesBottomSheetDialogFragment.UPDATE_CATEGORIES_KEY, true);
                        args.putStringArrayList(SelectWptCategoriesBottomSheetDialogFragment.ACTIVE_CATEGORIES_KEY, new ArrayList<String>(group.getWptCategories()));
                        SelectWptCategoriesBottomSheetDialogFragment fragment = new SelectWptCategoriesBottomSheetDialogFragment();
                        fragment.setArguments(args);
                        fragment.setUsedOnMap(false);
                        fragment.show(mapActivity.getSupportFragmentManager(), SelectWptCategoriesBottomSheetDialogFragment.TAG);
                    } else {
                        mapActivity.getMyApplication().getMapMarkersHelper().addOrEnableGpxGroup(new File(group.getGpxPath(app)));
                    }
                }
            };
            categoriesViewHolder.title.setText(getGroupWptCategoriesString(group));
            categoriesViewHolder.divider.setVisibility(View.VISIBLE);
            categoriesViewHolder.button.setCompoundDrawablesWithIntrinsicBounds(null, null, app.getUIUtilities().getIcon(R.drawable.ic_action_filter, night ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light), null);
            categoriesViewHolder.button.setOnClickListener(openChooseCategoriesDialog);
            categoriesViewHolder.title.setOnClickListener(openChooseCategoriesDialog);
        }
    }
}
Also used : MapMarker(net.osmand.plus.mapmarkers.MapMarker) GroupHeader(net.osmand.plus.mapmarkers.GroupHeader) ArrayList(java.util.ArrayList) SelectWptCategoriesBottomSheetDialogFragment(net.osmand.plus.mapmarkers.SelectWptCategoriesBottomSheetDialogFragment) MapMarkersGroup(net.osmand.plus.mapmarkers.MapMarkersGroup) ImageView(android.widget.ImageView) Bundle(android.os.Bundle) Calendar(java.util.Calendar) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) UiUtilities(net.osmand.plus.utils.UiUtilities) LatLon(net.osmand.data.LatLon) MapMarkersHelper(net.osmand.plus.mapmarkers.MapMarkersHelper) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) TravelArticle(net.osmand.plus.wikivoyage.data.TravelArticle) ShowHideHistoryButton(net.osmand.plus.mapmarkers.ShowHideHistoryButton) GPXFile(net.osmand.GPXUtilities.GPXFile) SelectedGpxFile(net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile) GPXFile(net.osmand.GPXUtilities.GPXFile) File(java.io.File) CompoundButton(android.widget.CompoundButton)

Example 29 with UiUtilities

use of net.osmand.plus.utils.UiUtilities in project Osmand by osmandapp.

the class AudioVideoNoteRecordingMenu method update.

public void update() {
    CurrentRecording recording = plugin.getCurrentRecording();
    UiUtilities iconsCache = requireMapActivity().getMyApplication().getUIUtilities();
    ImageView leftButtonIcon = (ImageView) view.findViewById(R.id.leftButtonIcon);
    View leftButtonView = view.findViewById(R.id.leftButtonView);
    if (recording.getType() != AVActionType.REC_AUDIO) {
        leftButtonIcon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_minimize));
        TextView showHideText = (TextView) view.findViewById(R.id.leftButtonText);
        showHideText.setText(showViewfinder ? view.getResources().getString(R.string.shared_string_hide) : view.getResources().getString(R.string.shared_string_show));
        leftButtonView.setVisibility(View.VISIBLE);
        viewfinder.setVisibility(showViewfinder ? View.VISIBLE : View.GONE);
    } else {
        leftButtonView.setVisibility(View.INVISIBLE);
        viewfinder.setVisibility(View.GONE);
    }
    leftButtonView.setOnClickListener(v -> showHideViewfinder());
    View centerButtonView = view.findViewById(R.id.centerButtonView);
    ImageView recIcon = (ImageView) view.findViewById(R.id.centerButtonIcon);
    TextView recText = (TextView) view.findViewById(R.id.centerButtonText);
    View timeView = view.findViewById(R.id.timeView);
    switch(recording.getType()) {
        case REC_AUDIO:
        case REC_VIDEO:
            recIcon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_rec_stop));
            recText.setText(view.getResources().getString(R.string.shared_string_control_stop));
            recText.setVisibility(View.VISIBLE);
            updateDuration();
            timeView.setVisibility(View.VISIBLE);
            break;
        case REC_PHOTO:
            recIcon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_photo_dark));
            recText.setVisibility(View.GONE);
            timeView.setVisibility(View.INVISIBLE);
            break;
    }
    centerButtonView.setOnClickListener(v -> rec(requireMapActivity(), false));
    applyViewfinderVisibility();
}
Also used : UiUtilities(net.osmand.plus.utils.UiUtilities) CurrentRecording(net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin.CurrentRecording) TextView(android.widget.TextView) ImageView(android.widget.ImageView) SurfaceView(android.view.SurfaceView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View)

Example 30 with UiUtilities

use of net.osmand.plus.utils.UiUtilities in project Osmand by osmandapp.

the class GPXAction method setupGpxTrackInfo.

private void setupGpxTrackInfo(@NonNull View trackInfoContainer, @NonNull String gpxName, @NonNull GPXTrackAnalysis analysis, @NonNull OsmandApplication app) {
    UiUtilities iconsCache = app.getUIUtilities();
    TextView title = trackInfoContainer.findViewById(R.id.title);
    title.setText(gpxName);
    title.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
    ImageView trackIcon = trackInfoContainer.findViewById(R.id.icon);
    trackIcon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_polygom_dark));
    ImageView distanceIcon = trackInfoContainer.findViewById(R.id.distance_icon);
    TextView distanceText = trackInfoContainer.findViewById(R.id.distance);
    distanceIcon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_distance_16));
    distanceText.setText(OsmAndFormatter.getFormattedDistance(analysis.totalDistance, app));
    ImageView waypointsIcon = trackInfoContainer.findViewById(R.id.points_icon);
    TextView waypointsCountText = trackInfoContainer.findViewById(R.id.points_count);
    waypointsIcon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_waypoint_16));
    waypointsCountText.setText(String.valueOf(analysis.wptPoints));
    ImageView timeIcon = trackInfoContainer.findViewById(R.id.time_icon);
    if (analysis.isTimeSpecified()) {
        AndroidUiHelper.updateVisibility(timeIcon, true);
        timeIcon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_time_16));
        TextView timeText = trackInfoContainer.findViewById(R.id.time);
        int duration = (int) (analysis.timeSpan / 1000);
        timeText.setText(Algorithms.formatDuration(duration, app.accessibilityEnabled()));
    } else {
        AndroidUiHelper.updateVisibility(timeIcon, false);
    }
}
Also used : UiUtilities(net.osmand.plus.utils.UiUtilities) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Aggregations

UiUtilities (net.osmand.plus.utils.UiUtilities)35 View (android.view.View)16 ImageView (android.widget.ImageView)16 Drawable (android.graphics.drawable.Drawable)13 TextView (android.widget.TextView)13 OsmandApplication (net.osmand.plus.OsmandApplication)13 MenuItem (android.view.MenuItem)7 ArrayList (java.util.ArrayList)7 MapActivity (net.osmand.plus.activities.MapActivity)7 LatLon (net.osmand.data.LatLon)6 PopupMenu (androidx.appcompat.widget.PopupMenu)5 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 SuppressLint (android.annotation.SuppressLint)3 Bundle (android.os.Bundle)3 Editable (android.text.Editable)3 TextWatcher (android.text.TextWatcher)3 LayoutInflater (android.view.LayoutInflater)3 MotionEvent (android.view.MotionEvent)3 AdapterView (android.widget.AdapterView)3 PointDescription (net.osmand.data.PointDescription)3