|
36 | 36 | import android.telephony.TelephonyManager; |
37 | 37 | import android.text.Spannable; |
38 | 38 | import android.text.SpannableString; |
| 39 | +import android.text.SpannableStringBuilder; |
39 | 40 | import android.text.Spanned; |
40 | 41 | import android.text.style.AbsoluteSizeSpan; |
| 42 | +import android.text.style.ClickableSpan; |
41 | 43 | import android.text.style.ForegroundColorSpan; |
42 | 44 | import android.text.style.ImageSpan; |
43 | 45 | import android.text.style.StyleSpan; |
| 46 | +import android.text.style.URLSpan; |
44 | 47 | import android.view.KeyEvent; |
| 48 | +import android.view.View; |
45 | 49 | import android.view.Window; |
46 | 50 | import android.view.WindowManager; |
47 | 51 | import android.view.inputmethod.BaseInputConnection; |
48 | 52 |
|
| 53 | +import androidx.annotation.NonNull; |
49 | 54 | import androidx.browser.customtabs.CustomTabsIntent; |
50 | 55 | import androidx.core.app.NotificationCompat; |
51 | 56 | import androidx.core.content.ContextCompat; |
@@ -1239,6 +1244,30 @@ public static boolean isSystemGestureArrowEnabled(Context context) { |
1239 | 1244 | return false; |
1240 | 1245 | } |
1241 | 1246 |
|
| 1247 | + /** |
| 1248 | + * Make link open in browser. Not working. |
| 1249 | + */ |
| 1250 | + public static CharSequence toBrowserLink(Context context, CharSequence message) { |
| 1251 | + SpannableStringBuilder builder = SpannableStringBuilder.valueOf(message); |
| 1252 | + URLSpan[] spans = builder.getSpans(0, builder.length(), URLSpan.class); |
| 1253 | + |
| 1254 | + for (URLSpan span : spans) { |
| 1255 | + builder.setSpan(new ClickableSpan() { |
| 1256 | + @Override |
| 1257 | + public void onClick(@NonNull View widget) { |
| 1258 | + MessageHelpers.showMessage(context, "On link clicked " + span.getURL()); |
| 1259 | + } |
| 1260 | + }, |
| 1261 | + builder.getSpanStart(span), |
| 1262 | + builder.getSpanEnd(span), |
| 1263 | + Spanned.SPAN_INCLUSIVE_EXCLUSIVE |
| 1264 | + ); |
| 1265 | + builder.removeSpan(span); |
| 1266 | + } |
| 1267 | + |
| 1268 | + return builder; |
| 1269 | + } |
| 1270 | + |
1242 | 1271 | private static void persistData(Context context) { |
1243 | 1272 | VideoStateService.instance(context).persistNow(); |
1244 | 1273 | PlayerData.instance(context).persistNow(); |
|
0 commit comments