Fix usage of deprecated function String.fromHtml(String)

String.fromHtml(String) is now deprecated. This patch fixes that by adding a method to Utils that selects the appropriate function based on the user's platform.
This commit is contained in:
Deskana 2017-05-26 13:52:01 +01:00
parent 67dfa170d2
commit 14326ae3d0
2 changed files with 19 additions and 2 deletions

View file

@ -2,7 +2,10 @@ package fr.free.nrw.commons;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.preference.PreferenceManager;
import android.text.Html;
import android.text.Spanned;
import fr.free.nrw.commons.settings.Prefs;
import timber.log.Timber;
@ -78,6 +81,19 @@ public class Utils {
}
}
/** Fix Html.fromHtml is deprecated problem
* @param source provided Html string
* @return returned Spanned of appropriate method according to version check
* */
public static Spanned fromHtml(String source) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return Html.fromHtml(source, Html.FROM_HTML_MODE_LEGACY);
} else {
//noinspection deprecation
return Html.fromHtml(source);
}
}
/**
* Strips localization symbols from a string.
* Removes the suffix after "@" and quotes.

View file

@ -2,10 +2,11 @@ package fr.free.nrw.commons.ui.widget;
import android.content.Context;
import android.support.v7.widget.AppCompatTextView;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.util.AttributeSet;
import fr.free.nrw.commons.Utils;
/**
* An {@link AppCompatTextView} which formats the text to HTML displayable text and makes any
* links clickable.
@ -16,6 +17,6 @@ public class HtmlTextView extends AppCompatTextView {
super(context, attrs);
setMovementMethod(LinkMovementMethod.getInstance());
setText(Html.fromHtml(getText().toString()));
setText(Utils.fromHtml(getText().toString()));
}
}