Merge pull request #5420 from osmandapp/TransportRoutesImprovements

Transport routes improvements
This commit is contained in:
Alexey 2018-05-17 15:43:54 +03:00 committed by GitHub
commit bfa0be49b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 20 deletions

View file

@ -133,7 +133,7 @@
android:textColor="?attr/wikivoyage_active_color"
android:textSize="@dimen/text_button_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:drawableLeft="@drawable/ic_action_track_16"
tools:drawableLeft="@drawable/ic_action_markers_dark"
tools:drawableTint="?attr/wikivoyage_active_color"
tools:ignore="UnusedAttribute" />

View file

@ -7,6 +7,8 @@ import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
@ -23,6 +25,7 @@ import android.text.SpannableString;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.text.style.ImageSpan;
import android.text.style.URLSpan;
import android.util.DisplayMetrics;
import android.util.TypedValue;
@ -58,7 +61,7 @@ public class AndroidUtils {
public static boolean isHardwareKeyboardAvailable(Context context) {
return context.getResources().getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS;
}
public static void softKeyboardDelayed(final View view) {
view.post(new Runnable() {
@Override
@ -106,6 +109,30 @@ public class AndroidUtils {
return src;
}
public static Spannable replaceCharsWithIcon(String text, Drawable icon, String[] chars) {
Spannable spannable = new SpannableString(text);
for (String entry : chars) {
int i = text.indexOf(entry, 0);
while (i < text.length() && i != -1) {
ImageSpan span = new ImageSpan(icon) {
public void draw(Canvas canvas, CharSequence text, int start, int end,
float x, int top, int y, int bottom, Paint paint) {
Drawable drawable = getDrawable();
canvas.save();
int transY = bottom - drawable.getBounds().bottom;
transY -= paint.getFontMetricsInt().descent / 2;
canvas.translate(x, transY);
drawable.draw(canvas);
canvas.restore();
}
};
spannable.setSpan(span, i, i + entry.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
i = text.indexOf(entry, i + entry.length());
}
}
return spannable;
}
public static void removeLinkUnderline(TextView textView) {
Spannable s = new SpannableString(textView.getText());
for (URLSpan span : s.getSpans(0, s.length(), URLSpan.class)) {

View file

@ -15,11 +15,7 @@ import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.view.ContextThemeWrapper;
import android.text.ClipboardManager;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.DynamicDrawableSpan;
import android.text.style.ImageSpan;
import android.text.util.Linkify;
import android.util.TypedValue;
import android.view.Gravity;
@ -74,6 +70,7 @@ public class MenuBuilder {
public static final float SHADOW_HEIGHT_TOP_DP = 17f;
public static final int TITLE_LIMIT = 60;
protected static final String[] arrowChars = new String[]{"=>"," - "};
protected MapActivity mapActivity;
protected MapContextMenu mapContextMenu;
@ -829,19 +826,10 @@ public class MenuBuilder {
titleView.setTextSize(16);
titleView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_bottom_view_text_color_light : R.color.ctx_menu_bottom_view_text_color_dark));
String desc = route.getDescription(getMapActivity().getMyApplication(), true);
SpannableString stringWithImage = new SpannableString(desc);
if (desc.contains("=>") || desc.contains(" - ")) {
Drawable arrow = app.getIconsCache().getIcon(R.drawable.ic_arrow_right_16, light ? R.color.ctx_menu_route_icon_color_light : R.color.ctx_menu_route_icon_color_dark);
arrow.setBounds(0, 0, arrow.getIntrinsicWidth(), arrow.getIntrinsicHeight());
int replaceIndex = desc.indexOf("=>");
if (replaceIndex != -1) {
stringWithImage.setSpan(new ImageSpan(arrow, DynamicDrawableSpan.ALIGN_BASELINE), replaceIndex, replaceIndex + 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
replaceIndex = desc.indexOf(" - ") + 1;
stringWithImage.setSpan(new ImageSpan(arrow, DynamicDrawableSpan.ALIGN_BASELINE), replaceIndex, replaceIndex + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
titleView.setText(stringWithImage);
Drawable arrow = app.getIconsCache().getIcon(R.drawable.ic_arrow_right_16, light ? R.color.ctx_menu_route_icon_color_light : R.color.ctx_menu_route_icon_color_dark);
arrow.setBounds(0, 0, arrow.getIntrinsicWidth(), arrow.getIntrinsicHeight());
titleView.setText(AndroidUtils.replaceCharsWithIcon(desc, arrow, arrowChars));
infoView.addView(titleView);
LinearLayout typeView = new LinearLayout(view.getContext());

View file

@ -130,7 +130,7 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme
trackButton = (TextView) mainView.findViewById(R.id.gpx_button);
trackButton.setCompoundDrawablesWithIntrinsicBounds(
getActiveIcon(R.drawable.ic_action_track_16), null, null, null
getActiveIcon(R.drawable.ic_action_markers_dark), null, null, null
);
trackButton.setOnClickListener(new View.OnClickListener() {
@Override