Merge pull request #7718 from osmandapp/context_menu_description

Context menu description improvements
This commit is contained in:
max-klaus 2019-10-22 15:10:14 +03:00 committed by GitHub
commit 61fabcba77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 161 additions and 185 deletions

View file

@ -56,8 +56,10 @@ import net.osmand.plus.mapcontextmenu.builders.cards.NoImagesCard;
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.views.POIMapLayer;
import net.osmand.plus.views.TransportStopsLayer;
import net.osmand.plus.widgets.TextViewEx;
import net.osmand.plus.widgets.tools.ClickableSpanTouchListener;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
@ -471,6 +473,7 @@ public class MenuBuilder {
}
protected void buildTopInternal(View view) {
buildDescription(view);
if (showLocalTransportRoutes()) {
buildRow(view, 0, null, app.getString(R.string.transport_Routes), 0, true, getCollapsableTransportStopRoutesView(view.getContext(), false, false),
false, 0, false, null, true);
@ -483,6 +486,9 @@ public class MenuBuilder {
}
}
protected void buildDescription(View view){
}
protected void buildAfter(View view) {
buildRowDivider(view);
}
@ -505,20 +511,20 @@ public class MenuBuilder {
public View buildRow(final View view, Drawable icon, final String buttonText, final String text, int textColor, String secondaryText,
boolean collapsable, final CollapsableView collapsableView, boolean needLinks,
int textLinesLimit, boolean isUrl, OnClickListener onClickListener, boolean matchWidthDivider) {
return buildRow(view, icon, buttonText, text, textColor, secondaryText, collapsable, collapsableView,
return buildRow(view, icon, buttonText, null, text, textColor, secondaryText, collapsable, collapsableView,
needLinks, textLinesLimit, isUrl, false, false, onClickListener, matchWidthDivider);
}
public View buildRow(View view, int iconId, String buttonText, String text, int textColor,
boolean collapsable, final CollapsableView collapsableView,
boolean needLinks, int textLinesLimit, boolean isUrl, boolean isNumber, boolean isEmail, OnClickListener onClickListener, boolean matchWidthDivider) {
return buildRow(view, iconId == 0 ? null : getRowIcon(iconId), buttonText, text, textColor, null, collapsable, collapsableView,
return buildRow(view, iconId == 0 ? null : getRowIcon(iconId), buttonText, null, text, textColor, null, collapsable, collapsableView,
needLinks, textLinesLimit, isUrl, isNumber, isEmail, onClickListener, matchWidthDivider);
}
public View buildRow(final View view, Drawable icon, final String buttonText, final String text, int textColor, String secondaryText,
boolean collapsable, final CollapsableView collapsableView, boolean needLinks,
int textLinesLimit, boolean isUrl, boolean isNumber, boolean isEmail, OnClickListener onClickListener, boolean matchWidthDivider) {
public View buildRow(final View view, Drawable icon, final String buttonText, final String textPrefix, final String text,
int textColor, String secondaryText, boolean collapsable, final CollapsableView collapsableView, boolean needLinks,
int textLinesLimit, boolean isUrl, boolean isNumber, boolean isEmail, OnClickListener onClickListener, boolean matchWidthDivider) {
if (!isFirstRow()) {
buildRowDivider(view);
@ -537,7 +543,8 @@ public class MenuBuilder {
ll.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
copyToClipboard(text, view.getContext());
String textToCopy = Algorithms.isEmpty(textPrefix) ? text : textPrefix + ": " + text;
copyToClipboard(textToCopy, view.getContext());
return true;
}
});
@ -572,30 +579,46 @@ public class MenuBuilder {
llText.setLayoutParams(llTextViewParams);
ll.addView(llText);
TextViewEx textPrefixView = null;
if (!Algorithms.isEmpty(textPrefix)) {
textPrefixView = new TextViewEx(view.getContext());
LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
llTextParams.setMargins(icon == null ? dpToPx(16f) : 0, dpToPx(8f), 0, 0);
textPrefixView.setLayoutParams(llTextParams);
textPrefixView.setTypeface(FontCache.getRobotoRegular(view.getContext()));
textPrefixView.setTextSize(12);
textPrefixView.setTextColor(app.getResources().getColor(light ? R.color.text_color_secondary_light: R.color.text_color_secondary_dark));
textPrefixView.setMinLines(1);
textPrefixView.setMaxLines(1);
textPrefixView.setText(textPrefix);
llText.addView(textPrefixView);
}
// Primary text
TextViewEx textView = new TextViewEx(view.getContext());
LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
llTextParams.setMargins(icon != null ? 0 : dpToPx(16f), dpToPx(secondaryText != null ? 10f : 8f), 0, dpToPx(secondaryText != null ? 6f : 8f));
llTextParams.setMargins(icon != null ? 0 : dpToPx(16f), dpToPx(textPrefixView != null ? 2f : (secondaryText != null ? 10f : 8f)), 0, dpToPx(secondaryText != null ? 6f : 8f));
textView.setLayoutParams(llTextParams);
textView.setTypeface(FontCache.getRobotoRegular(view.getContext()));
textView.setTextSize(16);
textView.setTextColor(app.getResources().getColor(light ? R.color.text_color_primary_light : R.color.text_color_primary_dark));
textView.setText(text);
int linkTextColor = ContextCompat.getColor(view.getContext(), light ? R.color.ctx_menu_bottom_view_url_color_light : R.color.ctx_menu_bottom_view_url_color_dark);
if (isUrl || isNumber || isEmail) {
textView.setTextColor(linkTextColor);
} else if (needLinks) {
Linkify.addLinks(textView, Linkify.ALL);
textView.setLinksClickable(true);
} else if (needLinks && Linkify.addLinks(textView, Linkify.ALL)) {
textView.setMovementMethod(null);
textView.setLinkTextColor(linkTextColor);
textView.setOnTouchListener(new ClickableSpanTouchListener());
AndroidUtils.removeLinkUnderline(textView);
}
if (textLinesLimit > 0) {
textView.setMinLines(1);
textView.setMaxLines(textLinesLimit);
textView.setEllipsize(TextUtils.TruncateAt.END);
}
textView.setText(text);
if (textColor > 0) {
textView.setTextColor(view.getResources().getColor(textColor));
}
@ -706,7 +729,21 @@ public class MenuBuilder {
return ll;
}
public View buildDescriptionRow(final View view, final String textPrefix, final String description, int textColor,
int textLinesLimit, boolean matchWidthDivider) {
OnClickListener clickListener = new OnClickListener() {
@Override
public void onClick(View v) {
POIMapLayer.showDescriptionDialog(view.getContext(), app, description, textPrefix);
}
};
return buildRow(view, null, null, textPrefix, description, textColor,
null, false, null, true, textLinesLimit,
false, false, false, clickListener, matchWidthDivider);
}
protected void showDialog(String text, final String actionType, final String dataPrefix, final View v) {
final String[] items = text.split("[,;]");
final Intent intent = new Intent(actionType);

View file

@ -1,7 +1,6 @@
package net.osmand.plus.mapcontextmenu.builders;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
@ -9,7 +8,6 @@ import android.net.Uri;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.view.ContextThemeWrapper;
import android.text.TextUtils;
import android.text.util.Linkify;
@ -23,13 +21,16 @@ import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.data.Amenity;
import net.osmand.data.PointDescription;
import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiType;
import net.osmand.plus.*;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
@ -37,11 +38,13 @@ import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.views.POIMapLayer;
import net.osmand.plus.widgets.TextViewEx;
import net.osmand.plus.widgets.tools.ClickableSpanTouchListener;
import net.osmand.plus.wikipedia.WikiArticleHelper;
import net.osmand.plus.wikipedia.WikipediaArticleWikiLinkFragment;
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
import net.osmand.util.Algorithms;
import net.osmand.util.OpeningHoursParser;
import org.apache.commons.logging.Log;
import java.math.RoundingMode;
@ -173,10 +176,10 @@ public class AmenityMenuBuilder extends MenuBuilder {
needLinks = false;
}
textView.setText(text);
if (needLinks) {
Linkify.addLinks(textView, Linkify.ALL);
textView.setLinksClickable(true);
if (needLinks && Linkify.addLinks(textView, Linkify.ALL)) {
textView.setMovementMethod(null);
textView.setLinkTextColor(linkTextColor);
textView.setOnTouchListener(new ClickableSpanTouchListener());
AndroidUtils.removeLinkUnderline(textView);
}
textView.setEllipsize(TextUtils.TruncateAt.END);

View file

@ -3,15 +3,9 @@ package net.osmand.plus.mapcontextmenu.builders;
import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.ResultMatcher;
import net.osmand.binary.BinaryMapIndexReader;
@ -27,7 +21,6 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.routing.TransportRoutingHelper;
import net.osmand.plus.widgets.TextViewEx;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
@ -73,7 +66,6 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
@Override
protected void buildTopInternal(View view) {
buildDescription(view);
super.buildTopInternal(view);
buildGroupFavouritesView(view);
}
@ -88,6 +80,14 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
}
}
@Override
protected void buildDescription(View view) {
String desc = fav.getDescription();
if (!Algorithms.isEmpty(desc)) {
buildDescriptionRow(view, app.getString(R.string.shared_string_description), desc, 0, 10, true);
}
}
private void buildGroupFavouritesView(View view) {
FavoriteGroup favoriteGroup = app.getFavorites().getGroup(fav);
List<FavouritePoint> groupFavourites = favoriteGroup.points;
@ -102,84 +102,6 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
}
}
private void buildDescriptionRow(final View view, final String description, int textColor,
int textLinesLimit, boolean matchWidthDivider) {
if (!isFirstRow()) {
buildRowDivider(view);
}
LinearLayout baseView = new LinearLayout(view.getContext());
baseView.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams llBaseViewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
baseView.setLayoutParams(llBaseViewParams);
LinearLayout ll = new LinearLayout(view.getContext());
ll.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
ll.setLayoutParams(llParams);
ll.setBackgroundResource(AndroidUtils.resolveAttribute(view.getContext(), android.R.attr.selectableItemBackground));
ll.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
copyToClipboard(description, view.getContext());
return true;
}
});
baseView.addView(ll);
// Text
LinearLayout llText = new LinearLayout(view.getContext());
llText.setOrientation(LinearLayout.VERTICAL);
ll.addView(llText);
TextView textPrefixView = new TextView(view.getContext());
LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
llTextParams.setMargins(dpToPx(16f), dpToPx(8f), 0, 0);
textPrefixView.setLayoutParams(llTextParams);
textPrefixView.setTextSize(12);
textPrefixView.setTextColor(app.getResources().getColor(R.color.ctx_menu_buttons_text_color));
textPrefixView.setEllipsize(TextUtils.TruncateAt.END);
textPrefixView.setMinLines(1);
textPrefixView.setMaxLines(1);
textPrefixView.setText(app.getResources().getString(R.string.shared_string_description));
llText.addView(textPrefixView);
TextView textView = new TextView(view.getContext());
LinearLayout.LayoutParams llTextParams2 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
llTextParams2.setMargins(dpToPx(16f), dpToPx(2f), 0, dpToPx(8f));
textView.setLayoutParams(llTextParams2);
textView.setTextSize(16);
textView.setTextColor(app.getResources().getColor(light ? R.color.text_color_primary_light : R.color.text_color_primary_dark));
textView.setText(description);
textView.setEllipsize(TextUtils.TruncateAt.END);
if (textLinesLimit > 0) {
textView.setMinLines(1);
textView.setMaxLines(textLinesLimit);
}
if (textColor > 0) {
textView.setTextColor(view.getResources().getColor(textColor));
}
llText.addView(textView);
LinearLayout.LayoutParams llTextViewParams = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT);
llTextViewParams.weight = 1f;
llTextViewParams.setMargins(0, 0, dpToPx(10f), 0);
llTextViewParams.gravity = Gravity.CENTER_VERTICAL;
llText.setLayoutParams(llTextViewParams);
((LinearLayout) view).addView(baseView);
rowBuilt();
setDividerWidth(matchWidthDivider);
}
private void buildDescription(View view) {
String desc = fav.getDescription();
if (!Algorithms.isEmpty(desc)) {
buildDescriptionRow(view, desc, 0, 0, true);
}
}
private Amenity findAmenity(String nameStringEn, double lat, double lon) {
QuadRect rect = MapUtils.calculateLatLonBbox(lat, lon, 15);
List<Amenity> amenities = app.getResourceManager().searchAmenities(

View file

@ -8,10 +8,10 @@ import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.LinearLayout;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmAndAppCustomization;
@ -30,6 +30,7 @@ import java.util.Date;
import java.util.List;
public class WptPtMenuBuilder extends MenuBuilder {
private final WptPt wpt;
public WptPtMenuBuilder(@NonNull MapActivity mapActivity, final @NonNull WptPt wpt) {
@ -49,6 +50,13 @@ public class WptPtMenuBuilder extends MenuBuilder {
buildWaypointsView(view);
}
@Override
protected void buildDescription(View view) {
if (!Algorithms.isEmpty(wpt.desc)) {
buildDescriptionRow(view, app.getString(R.string.shared_string_description), wpt.desc, 0, 10, true);
}
}
@Override
public void buildInternal(View view) {
if (wpt.time > 0) {
@ -92,16 +100,7 @@ public class WptPtMenuBuilder extends MenuBuilder {
}
protected void prepareDescription(final WptPt wpt, View view) {
if (!Algorithms.isEmpty(wpt.desc)) {
final View row = buildRow(view, R.drawable.ic_action_note_dark, null, wpt.desc, 0, false, null, true, 10, false, null, false);
row.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
POIMapLayer.showDescriptionDialog(row.getContext(), app, wpt.desc,
row.getResources().getString(R.string.shared_string_description));
}
});
}
}
private void buildWaypointsView(View view) {

View file

@ -8,15 +8,10 @@ import android.support.v7.preference.CheckBoxPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.PreferenceViewHolder;
import android.text.Layout;
import android.text.Selection;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
@ -26,6 +21,7 @@ import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.settings.bottomsheets.ChangeGeneralProfilesPrefBottomSheet;
import net.osmand.plus.widgets.tools.ClickableSpanTouchListener;
import net.osmand.plus.wikipedia.WikipediaDialogFragment;
@ -72,53 +68,11 @@ public class CoordinatesFormatFragment extends BaseSettingsFragment {
if (UTM_FORMAT.equals(preference.getKey())) {
TextView summaryView = (TextView) holder.findViewById(android.R.id.summary);
if (summaryView != null) {
summaryView.setOnTouchListener(getSummaryTouchListener());
summaryView.setOnTouchListener(new ClickableSpanTouchListener());
}
}
}
private View.OnTouchListener getSummaryTouchListener() {
return new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
TextView widget = (TextView) v;
int x = (int) event.getX();
int y = (int) event.getY();
x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();
x += widget.getScrollX();
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
Spannable spannable = new SpannableString(widget.getText());
ClickableSpan[] links = spannable.getSpans(off, off, ClickableSpan.class);
if (links.length != 0) {
if (action == MotionEvent.ACTION_UP) {
links[0].onClick(widget);
} else {
Selection.setSelection(spannable, spannable.getSpanStart(links[0]), spannable.getSpanEnd(links[0]));
}
return true;
} else {
Selection.removeSelection(spannable);
}
}
return false;
}
};
}
private CharSequence getCoordinatesFormatSummary(Location loc, int format) {
double lat = loc != null ? loc.getLatitude() : 49.41869;
double lon = loc != null ? loc.getLongitude() : 8.67339;

View file

@ -0,0 +1,52 @@
package net.osmand.plus.widgets.tools;
import android.text.Layout;
import android.text.Selection;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ClickableSpan;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
public class ClickableSpanTouchListener implements View.OnTouchListener {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
TextView widget = (TextView) v;
int x = (int) event.getX();
int y = (int) event.getY();
x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();
x += widget.getScrollX();
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
Spannable spannable = new SpannableString(widget.getText());
ClickableSpan[] links = spannable.getSpans(off, off, ClickableSpan.class);
if (links.length != 0) {
if (action == MotionEvent.ACTION_UP) {
links[0].onClick(widget);
} else {
Selection.setSelection(spannable, spannable.getSpanStart(links[0]), spannable.getSpanEnd(links[0]));
}
return true;
} else {
Selection.removeSelection(spannable);
}
}
return false;
}
}

View file

@ -12,30 +12,37 @@ import net.osmand.util.Algorithms;
import java.util.HashMap;
public class WikivoyageWptPtMenuBuilder extends WptPtMenuBuilder {
private final static String KEY_PHONE = "Phone: ";
private final static String KEY_EMAIL = "Email: ";
private final static String KEY_WORKING_HOURS = "Working hours: ";
private final static String KEY_PRICE = "Price: ";
private final static String KEY_DIRECTIONS = "Directions: ";
private final static String KEY_DESCRIPTION = "Description";
private HashMap<String, String> descTokens;
public WikivoyageWptPtMenuBuilder(@NonNull MapActivity mapActivity, @NonNull WptPt wpt) {
super(mapActivity, wpt);
descTokens = getDescriptionTokens(wpt.desc, KEY_PHONE, KEY_EMAIL, KEY_WORKING_HOURS, KEY_PRICE, KEY_DIRECTIONS);
}
@Override
protected void buildDescription(View view) {
final String desc = descTokens.get(KEY_DESCRIPTION);
if (!Algorithms.isEmpty(desc)) {
buildDescriptionRow(view, app.getString(R.string.shared_string_description), desc, 0, 10, true);
}
}
@Override
protected void prepareDescription(final WptPt wpt, View view) {
HashMap<String, String> descTokens = getDescriptionTokens(wpt.desc, KEY_PHONE, KEY_EMAIL, KEY_WORKING_HOURS, KEY_PRICE, KEY_DIRECTIONS);
String phones = descTokens.get(KEY_PHONE);
String emails = descTokens.get(KEY_EMAIL);
String workingHours = descTokens.get(KEY_WORKING_HOURS);
String price = descTokens.get(KEY_PRICE);
String direction = descTokens.get(KEY_DIRECTIONS);
final String desc = descTokens.get(KEY_DESCRIPTION);
if (!Algorithms.isEmpty(desc)) {
buildRow(view, R.drawable.ic_action_note_dark, null, desc, 0, false, null, true, 10, false, null, false);
}
if (!Algorithms.isEmpty(phones)) {
buildRow(view, R.drawable.ic_action_call_dark,
null, phones, 0,
@ -68,23 +75,25 @@ public class WikivoyageWptPtMenuBuilder extends WptPtMenuBuilder {
}
}
private HashMap<String, String> getDescriptionTokens(String desc, String ... allowedKeys) {
String[] tokens = desc.split("\n");
private HashMap<String, String> getDescriptionTokens(String desc, String... allowedKeys) {
HashMap<String, String> mTokens = new HashMap<>();
for (String token : tokens) {
boolean matched = false;
for (String key : allowedKeys) {
if (token.startsWith(key)) {
matched = true;
String value = token.substring(key.length()).trim();
mTokens.put(key, value);
if (!Algorithms.isEmpty(desc)) {
String[] tokens = desc.split("\n");
for (String token : tokens) {
boolean matched = false;
for (String key : allowedKeys) {
if (token.startsWith(key)) {
matched = true;
String value = token.substring(key.length()).trim();
mTokens.put(key, value);
}
}
if (!matched) {
String s = mTokens.get(KEY_DESCRIPTION);
mTokens.put(KEY_DESCRIPTION, s != null ? s + "\n" + token : token);
}
}
if (!matched) {
String s = mTokens.get(KEY_DESCRIPTION);
mTokens.put(KEY_DESCRIPTION, s != null ? s + "\n" + token : token);
}
}
return mTokens;
}
}
}