Search in sources :

Example 1 with DirectionDrawable

use of net.osmand.plus.views.DirectionDrawable in project Osmand by osmandapp.

the class MapMarkerDialogHelper method updateMapMarkerInfo.

public static void updateMapMarkerInfo(final Context ctx, View localView, LatLon loc, Float heading, boolean useCenter, boolean nightMode, int screenOrientation, final MapMarker marker) {
    TextView text = (TextView) localView.findViewById(R.id.waypoint_text);
    TextView textShadow = (TextView) localView.findViewById(R.id.waypoint_text_shadow);
    TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
    ImageView arrow = (ImageView) localView.findViewById(R.id.direction);
    ImageView waypointIcon = (ImageView) localView.findViewById(R.id.waypoint_icon);
    TextView waypointDeviation = (TextView) localView.findViewById(R.id.waypoint_deviation);
    TextView descText = (TextView) localView.findViewById(R.id.waypoint_desc_text);
    final CheckBox checkBox = (CheckBox) localView.findViewById(R.id.checkbox);
    TextView dateGroupText = (TextView) localView.findViewById(R.id.date_group_text);
    if (text == null || textDist == null || arrow == null || waypointIcon == null || waypointDeviation == null || descText == null) {
        return;
    }
    float[] mes = new float[2];
    if (loc != null && marker.point != null) {
        Location.distanceBetween(marker.getLatitude(), marker.getLongitude(), loc.getLatitude(), loc.getLongitude(), mes);
    }
    boolean newImage = false;
    int arrowResId = R.drawable.ic_direction_arrow;
    DirectionDrawable dd;
    if (!(arrow.getDrawable() instanceof DirectionDrawable)) {
        newImage = true;
        dd = new DirectionDrawable(ctx, arrow.getWidth(), arrow.getHeight());
    } else {
        dd = (DirectionDrawable) arrow.getDrawable();
    }
    if (!marker.history) {
        dd.setImage(arrowResId, useCenter ? R.color.color_distance : R.color.color_myloc_distance);
    } else {
        dd.setImage(arrowResId, nightMode ? R.color.secondary_text_dark : R.color.secondary_text_light);
    }
    if (loc == null || heading == null || marker.point == null) {
        dd.setAngle(0);
    } else {
        dd.setAngle(mes[1] - heading + 180 + screenOrientation);
    }
    if (newImage) {
        arrow.setImageDrawable(dd);
    }
    arrow.setVisibility(View.VISIBLE);
    arrow.invalidate();
    final OsmandApplication app = (OsmandApplication) ctx.getApplicationContext();
    if (!marker.history) {
        waypointIcon.setImageDrawable(getMapMarkerIcon(app, marker.colorIndex));
        AndroidUtils.setTextPrimaryColor(ctx, text, nightMode);
        textDist.setTextColor(ctx.getResources().getColor(useCenter ? R.color.color_distance : R.color.color_myloc_distance));
    } else {
        waypointIcon.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_flag_dark, !nightMode));
        AndroidUtils.setTextSecondaryColor(ctx, text, nightMode);
        AndroidUtils.setTextSecondaryColor(ctx, textDist, nightMode);
    }
    int dist = (int) mes[0];
    textDist.setText(OsmAndFormatter.getFormattedDistance(dist, app));
    waypointDeviation.setVisibility(View.GONE);
    String descr = marker.getName(app);
    if (textShadow != null) {
        textShadow.setText(descr);
    }
    text.setText(descr);
    descText.setVisibility(View.GONE);
    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);
    String desc = month + " " + day;
    String markerGroupName = marker.groupName;
    if (markerGroupName != null) {
        if (markerGroupName.equals("")) {
            markerGroupName = app.getString(R.string.shared_string_favorites);
        }
        desc += " • " + markerGroupName;
    }
    dateGroupText.setVisibility(View.VISIBLE);
    dateGroupText.setText(desc);
    checkBox.setVisibility(View.GONE);
    checkBox.setOnClickListener(null);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) CheckBox(android.widget.CheckBox) TextView(android.widget.TextView) DirectionDrawable(net.osmand.plus.views.DirectionDrawable) ImageView(android.widget.ImageView) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 2 with DirectionDrawable

use of net.osmand.plus.views.DirectionDrawable in project Osmand by osmandapp.

the class DashLocationFragment method updateLocationView.

public static void updateLocationView(boolean useCenter, LatLon fromLoc, Float h, ImageView arrow, int arrowResId, int imgColor, TextView txt, int textColor, LatLon toLoc, int screenOrientation, OsmandApplication app, Context ctx, boolean paint) {
    float[] mes = new float[2];
    if (fromLoc != null && toLoc != null) {
        Location.distanceBetween(toLoc.getLatitude(), toLoc.getLongitude(), fromLoc.getLatitude(), fromLoc.getLongitude(), mes);
    }
    if (arrow != null) {
        boolean newImage = false;
        if (arrowResId == 0) {
            arrowResId = R.drawable.ic_direction_arrow;
        }
        DirectionDrawable dd;
        if (!(arrow.getDrawable() instanceof DirectionDrawable)) {
            newImage = true;
            dd = new DirectionDrawable(ctx, arrow.getWidth(), arrow.getHeight());
        } else {
            dd = (DirectionDrawable) arrow.getDrawable();
        }
        dd.setImage(arrowResId, imgColor == 0 ? useCenter ? R.color.color_distance : R.color.color_myloc_distance : imgColor);
        if (fromLoc == null || h == null || toLoc == null) {
            dd.setAngle(0);
        } else {
            dd.setAngle(mes[1] - h + 180 + screenOrientation);
        }
        if (newImage) {
            arrow.setImageDrawable(dd);
        }
        arrow.invalidate();
    }
    if (txt != null) {
        if (fromLoc != null && toLoc != null) {
            if (paint) {
                txt.setTextColor(app.getResources().getColor(textColor == 0 ? useCenter ? R.color.color_distance : R.color.color_myloc_distance : textColor));
            }
            txt.setText(OsmAndFormatter.getFormattedDistance(mes[0], app));
        } else {
            txt.setText("");
        }
    }
}
Also used : DirectionDrawable(net.osmand.plus.views.DirectionDrawable)

Example 3 with DirectionDrawable

use of net.osmand.plus.views.DirectionDrawable in project Osmand by osmandapp.

the class MapMarkersWidgetsFactory method updateUI.

private void updateUI(LatLon loc, Float heading, MapMarker marker, ImageView arrowImg, TextView distText, ImageButton okButton, TextView addressText, boolean firstLine, boolean customLocation) {
    float[] mes = new float[2];
    if (loc != null && marker.point != null) {
        Location.distanceBetween(marker.getLatitude(), marker.getLongitude(), loc.getLatitude(), loc.getLongitude(), mes);
    }
    if (customLocation) {
        heading = 0f;
    }
    boolean newImage = false;
    DirectionDrawable dd;
    if (!(arrowImg.getDrawable() instanceof DirectionDrawable)) {
        newImage = true;
        dd = new DirectionDrawable(map, arrowImg.getWidth(), arrowImg.getHeight());
    } else {
        dd = (DirectionDrawable) arrowImg.getDrawable();
    }
    dd.setImage(R.drawable.ic_arrow_marker_diretion, MapMarker.getColorId(marker.colorIndex));
    if (heading != null && loc != null) {
        dd.setAngle(mes[1] - heading + 180 + screenOrientation);
    }
    if (newImage) {
        arrowImg.setImageDrawable(dd);
    }
    arrowImg.invalidate();
    int dist = (int) mes[0];
    String txt;
    if (loc != null) {
        txt = OsmAndFormatter.getFormattedDistance(dist, map.getMyApplication());
    } else {
        txt = "—";
    }
    if (txt != null) {
        distText.setText(txt);
    }
    updateVisibility(okButton, !customLocation && loc != null && dist < MIN_DIST_OK_VISIBLE);
    String descr;
    PointDescription pd = marker.getPointDescription(map);
    if (Algorithms.isEmpty(pd.getName())) {
        descr = pd.getTypeName();
    } else {
        descr = pd.getName();
    }
    if (!firstLine && !isLandscapeLayout()) {
        descr = "  •  " + descr;
    }
    addressText.setText(descr);
}
Also used : PointDescription(net.osmand.data.PointDescription) DirectionDrawable(net.osmand.plus.views.DirectionDrawable)

Aggregations

DirectionDrawable (net.osmand.plus.views.DirectionDrawable)3 CheckBox (android.widget.CheckBox)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 PointDescription (net.osmand.data.PointDescription)1 OsmandApplication (net.osmand.plus.OsmandApplication)1