blob: 27fec7167a73fc9cdeb8544b4280daacd58b7453 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
package it.niedermann.owncloud.notes.shared.util;
import android.text.method.LinkMovementMethod;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.text.HtmlCompat;
/**
* Some helper functionality in alike the Android support library.
* Currently, it offers methods for working with HTML string resources.
*/
public class SupportUtil {
private SupportUtil() {
throw new UnsupportedOperationException("Do not instantiate this util class.");
}
/**
* Fills a {@link TextView} with HTML content and activates links in that {@link TextView}.
*
* @param view The {@link TextView} which should be filled.
* @param stringId The string resource containing HTML tags (escaped by <code><</code>)
* @param formatArgs Arguments for the string resource.
*/
public static void setHtml(@NonNull TextView view, int stringId, Object... formatArgs) {
view.setText(HtmlCompat.fromHtml(
view.getResources().getString(stringId, formatArgs), HtmlCompat.FROM_HTML_MODE_LEGACY));
view.setMovementMethod(LinkMovementMethod.getInstance());
}
}
|