android.text.util.Linkify Java Examples

The following examples show how to use android.text.util.Linkify. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScanDemoActivity.java    From Roid-Library with Apache License 2.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK && requestCode == 888) {
        String result = data.getExtras().getString("result");
        if (TextUtils.isEmpty(result)) {
            RLUiUtil.toast(this, R.string.scan_retry);
            return;
        }
        RLAlertDialog dialog = new RLAlertDialog(this, getString(R.string.scan_result), result, Linkify.ALL,
                getString(android.R.string.yes), getString(android.R.string.cancel), new RLAlertDialog.Listener() {
                    @Override
                    public void onLeftClick() {}

                    @Override
                    public void onRightClick() {}
                });
        dialog.show();
    }
}
 
Example #2
Source File: MainActivity.java    From BLE with Apache License 2.0 6 votes vote down vote up
/**
 * 显示项目信息
 */
private void displayAboutDialog() {
    final int paddingSizeDp = 5;
    final float scale = getResources().getDisplayMetrics().density;
    final int dpAsPixels = (int) (paddingSizeDp * scale + 0.5f);

    final TextView textView = new TextView(this);
    final SpannableString text = new SpannableString(getString(R.string.about_dialog_text));

    textView.setText(text);
    textView.setAutoLinkMask(RESULT_OK);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    textView.setPadding(dpAsPixels, dpAsPixels, dpAsPixels, dpAsPixels);

    Linkify.addLinks(text, Linkify.ALL);
    new AlertDialog.Builder(this).setTitle(R.string.menu_about).setCancelable(false).setPositiveButton(android.R
            .string.ok, null)
            .setView(textView).show();
}
 
Example #3
Source File: VoiceLanguageOptionsActivity.java    From your-local-weather with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    ((YourLocalWeather) getApplication()).applyTheme(this);
    super.onCreate(savedInstanceState);
    applicationLocale = new Locale(PreferenceUtil.getLanguage(this));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));
    }
    setContentView(R.layout.activity_voice_language_options);

    setupActionBar();
    TextView appLang = findViewById(R.id.pref_title_tts_lang_app_locale_id);
    appLang.setText(getString(R.string.pref_title_tts_lang_app_locale) + " " + applicationLocale.getDisplayName());
    TextView ttsAppGeneralInfo = findViewById(R.id.pref_title_tts_app_general_info_id);
    Linkify.addLinks(ttsAppGeneralInfo, Linkify.WEB_URLS);
    voiceSettingParametersDbHelper = VoiceSettingParametersDbHelper.getInstance(this);
}
 
Example #4
Source File: MainActivity.java    From BeMusic with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    final int id = item.getItemId();
    if (id == R.id.action_github) {
        Intents.openUrl(MainActivity.this, "https://github.com/boybeak/BeMusic");
    } else if (id == R.id.action_star_me) {
        Intents.viewMyAppOnStore(MainActivity.this);
    } else if (id == R.id.action_help) {
        final String message = getString(R.string.text_help);
        TextView messageTv = new TextView(MainActivity.this);
        final int padding = (int)(getResources().getDisplayMetrics().density * 24);
        messageTv.setPadding(padding, padding, padding, padding);
        messageTv.setAutoLinkMask(Linkify.WEB_URLS);
        messageTv.setText(message);

        new AlertDialog.Builder(MainActivity.this)
                .setTitle(R.string.title_menu_help)
                .setView(messageTv)
                .setPositiveButton(android.R.string.ok, null)
                .show();
    }
    mDrawerLayout.closeDrawers();
    return true;
}
 
Example #5
Source File: MessageFormatter.java    From talk-android with MIT License 6 votes vote down vote up
public static Spannable formatURLSpan(Spannable s) {
    Linkify.addLinks(s, Linkify.WEB_URLS);
    URLSpan[] urlSpans = s.getSpans(0, s.length(), URLSpan.class);
    for (URLSpan urlSpan : urlSpans) {
        final String url = urlSpan.getURL();
        final Matcher m = chinesePattern.matcher(url);
        if (m.find()) {
            s.removeSpan(urlSpan);
            continue;
        }
        int start = s.getSpanStart(urlSpan);
        int end = s.getSpanEnd(urlSpan);
        s.removeSpan(urlSpan);
        s.setSpan(new TalkURLSpan(urlSpan.getURL(), ThemeUtil.getThemeColor(MainApp.CONTEXT.
                        getResources(), BizLogic.getTeamColor())), start, end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    return s;
}
 
Example #6
Source File: MyActivity.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 6 votes vote down vote up
private void listing6_12() {
  // Listing 6-12: Creating custom link strings in Linkify

  // Define the base URI.
  String baseUri = "content://com.paad.earthquake/earthquakes/";

  // Construct an Intent to test if there is an Activity capable of
  // viewing the content you are Linkifying. Use the Package Manager
  // to perform the test.
  PackageManager pm = getPackageManager();
  Intent testIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(baseUri));
  boolean activityExists = testIntent.resolveActivity(pm) != null;

  // If there is an Activity capable of viewing the content
  // Linkify the text.
  if (activityExists) {
    int flags = Pattern.CASE_INSENSITIVE;
    Pattern p = Pattern.compile("\\bquake[\\s]?[0-9]+\\b", flags);
    Linkify.addLinks(myTextView, p, baseUri);
  }
}
 
Example #7
Source File: MainActivity.java    From twoh-android-material-design with MIT License 6 votes vote down vote up
public void open(){


        SpannableString str = new SpannableString("Copyright © : TWOh's Engineering " +
                "\nTutorial lengkap di http://www.twoh.co/mudengdroid-belajar-android-bersama-twohs-engineering/android-design-tutorial/");
        LinkifyCompat.addLinks(str, Linkify.WEB_URLS);
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        alertDialogBuilder.setMessage(str);
                alertDialogBuilder.setPositiveButton("OK",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface arg0, int arg1) {
                                arg0.dismiss();
                            }
                        });

        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();
    }
 
Example #8
Source File: LinkTransformationMethod.java    From EdXposedManager with GNU General Public License v3.0 6 votes vote down vote up
@Override
public CharSequence getTransformation(CharSequence source, View view) {
    if (view instanceof TextView) {
        TextView textView = (TextView) view;
        Linkify.addLinks(textView, Linkify.WEB_URLS);
        if (textView.getText() == null || !(textView.getText() instanceof Spannable)) {
            return source;
        }
        Spannable text = (Spannable) textView.getText();
        URLSpan[] spans = text.getSpans(0, textView.length(), URLSpan.class);
        for (int i = spans.length - 1; i >= 0; i--) {
            URLSpan oldSpan = spans[i];
            int start = text.getSpanStart(oldSpan);
            int end = text.getSpanEnd(oldSpan);
            String url = oldSpan.getURL();
            text.removeSpan(oldSpan);
            text.setSpan(new CustomTabsURLSpan(activity, url), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        return text;
    }
    return source;
}
 
Example #9
Source File: OutdatedReminder.java    From deltachat-android with GNU General Public License v3.0 6 votes vote down vote up
public OutdatedReminder(@NonNull final Context context) {
    super(context.getString(R.string.info_outdated_app_title),
            context.getString(R.string.info_outdated_app_text));

    setOkListener(v -> {
        AlertDialog sourceDialog = new AlertDialog.Builder(context)
                .setTitle(R.string.info_outdated_app_dialog_title)
                .setMessage(context.getString(R.string.info_outdated_app_dialog_text)
                    +"\n\nF-Droid: https://f-droid.org/packages/com.b44t.messenger"
                    +"\n\nGoogle Play: https://play.google.com/store/apps/details?id=chat.delta")
                .setPositiveButton(R.string.ok, (dialog, which) -> dialog.cancel())
                .create();
        sourceDialog.show();
        Linkify.addLinks((TextView) Objects.requireNonNull(sourceDialog.findViewById(android.R.id.message)), Linkify.WEB_URLS);
    });
}
 
Example #10
Source File: CustomHtmlToSpannedConverter.java    From zulip-android with Apache License 2.0 6 votes vote down vote up
/**
 * <<<<<<< e370c9bc00e8f6b33b1d12a44b4c70a7f063c8b9
 * Parses Spanned text for existing html links and reapplies them after the text has been Linkified
 * =======
 * Parses Spanned text for existing html links and reapplies them.
 * >>>>>>> Issue #168 bugfix for links not being clickable, adds autoLink feature including web, phone, map and email
 *
 * @param spann {@link Spanned} text which has to be Linkified
 * @param mask  bitmask to define which kinds of links will be searched and applied (e.g. <a href="https://developer.android.com/reference/android/text/util/Linkify.html#ALL">Linkify.ALL</a>)
 * @return Linkified {@link Spanned} text
 * @see <a href="https://developer.android.com/reference/android/text/util/Linkify.html">Linkify</a>
 */
public static Spanned linkifySpanned(@NonNull final Spanned spann, final int mask) {
    URLSpan[] existingSpans = spann.getSpans(0, spann.length(), URLSpan.class);
    List<Pair<Integer, Integer>> links = new ArrayList<>();

    for (URLSpan urlSpan : existingSpans) {
        links.add(new Pair<>(spann.getSpanStart(urlSpan), spann.getSpanEnd(urlSpan)));
    }

    Linkify.addLinks((Spannable) spann, mask);

    // add the links back in
    for (int i = 0; i < existingSpans.length; i++) {
        ((Spannable) spann).setSpan(existingSpans[i], links.get(i).first, links.get(i).second, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    return spann;
}
 
Example #11
Source File: LoginErrorDialog.java    From glimmr with Apache License 2.0 6 votes vote down vote up
@Override
public BaseDialogFragment.Builder build(BaseDialogFragment.Builder builder) {
    TextView message = new TextView(getActivity());
    message.setText(getString(R.string.login_error));
    Linkify.addLinks(message, Linkify.ALL);
    int padding = (int) getActivity().getResources()
            .getDimension(R.dimen.dialog_message_padding);
    builder.setView(message, padding, padding, padding, padding);
    builder.setTitle(getString(R.string.hmm));
    builder.setNegativeButton(getString(android.R.string.ok), new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    return builder;
}
 
Example #12
Source File: TextLinks.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/** Returns a new options object based on the specified link mask. */
public static Options fromLinkMask(@LinkifyMask int mask) {
    final List<String> entitiesToFind = new ArrayList<>();

    if ((mask & Linkify.WEB_URLS) != 0) {
        entitiesToFind.add(TextClassifier.TYPE_URL);
    }
    if ((mask & Linkify.EMAIL_ADDRESSES) != 0) {
        entitiesToFind.add(TextClassifier.TYPE_EMAIL);
    }
    if ((mask & Linkify.PHONE_NUMBERS) != 0) {
        entitiesToFind.add(TextClassifier.TYPE_PHONE);
    }
    if ((mask & Linkify.MAP_ADDRESSES) != 0) {
        entitiesToFind.add(TextClassifier.TYPE_ADDRESS);
    }

    return new Options().setEntityConfig(
            TextClassifier.EntityConfig.createWithEntityList(entitiesToFind));
}
 
Example #13
Source File: TextLinksParams.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a new TextLinksParams object based on the specified link mask.
 *
 * @param mask the link mask
 *      e.g. {@link LinkifyMask#PHONE_NUMBERS} | {@link LinkifyMask#EMAIL_ADDRESSES}
 * @hide
 */
@NonNull
public static TextLinksParams fromLinkMask(@LinkifyMask int mask) {
    final List<String> entitiesToFind = new ArrayList<>();
    if ((mask & Linkify.WEB_URLS) != 0) {
        entitiesToFind.add(TextClassifier.TYPE_URL);
    }
    if ((mask & Linkify.EMAIL_ADDRESSES) != 0) {
        entitiesToFind.add(TextClassifier.TYPE_EMAIL);
    }
    if ((mask & Linkify.PHONE_NUMBERS) != 0) {
        entitiesToFind.add(TextClassifier.TYPE_PHONE);
    }
    if ((mask & Linkify.MAP_ADDRESSES) != 0) {
        entitiesToFind.add(TextClassifier.TYPE_ADDRESS);
    }
    return new TextLinksParams.Builder().setEntityConfig(
            TextClassifier.EntityConfig.createWithExplicitEntityList(entitiesToFind))
            .build();
}
 
Example #14
Source File: TextMenuElement.java    From gravitydefied with GNU General Public License v2.0 6 votes vote down vote up
protected MenuTextView createTextView() {
	Context activity = getGDActivity();

	MenuTextView textView = new MenuTextView(activity);
	textView.setText(spanned);
	textView.setTextColor(TEXT_COLOR);
	textView.setTextSize(TEXT_SIZE);
	textView.setLineSpacing(0f, 1.5f);
	textView.setLayoutParams(new ViewGroup.LayoutParams(
			ViewGroup.LayoutParams.MATCH_PARENT,
			ViewGroup.LayoutParams.WRAP_CONTENT
	));

	Linkify.addLinks(textView, Linkify.WEB_URLS);
	textView.setLinksClickable(true);

	return textView;
}
 
Example #15
Source File: RcvHolder.java    From FamilyChat with Apache License 2.0 5 votes vote down vote up
/**
 * 设置textview支持超链接
 */
public RcvHolder setTvLinkify(int viewId)
{
    TextView tv = findView(viewId);
    if (tv != null)
        Linkify.addLinks(tv, Linkify.ALL);
    return this;
}
 
Example #16
Source File: SampleDialogFragment.java    From BlurDialogFragment with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_fragment, null);
    TextView label = ((TextView) view.findViewById(R.id.textView));
    label.setMovementMethod(LinkMovementMethod.getInstance());
    Linkify.addLinks(label, Linkify.WEB_URLS);
    builder.setView(view);
    return builder.create();
}
 
Example #17
Source File: SampleSupportDialogFragment.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    View customView = getActivity().getLayoutInflater().inflate(R.layout.blur_dialog_dialog_fragment, null);
    TextView label = ((TextView) customView.findViewById(R.id.textView));
    label.setMovementMethod(LinkMovementMethod.getInstance());
    Linkify.addLinks(label, Linkify.WEB_URLS);
    builder.setView(customView);
    return builder.create();
}
 
Example #18
Source File: IssueInfoAdapter.java    From glide-support with The Unlicense 5 votes vote down vote up
public TestInfoViewHolder(View itemView) {
	super(itemView);
	icon = (ImageView)itemView.findViewById(android.R.id.icon);
	title = (TextView)itemView.findViewById(android.R.id.title);
	clazz = (TextView)itemView.findViewById(android.R.id.text1);
	link = (TextView)itemView.findViewById(android.R.id.text2);
	link.setLinksClickable(true);
	link.setAutoLinkMask(Linkify.WEB_URLS);
	link.setMovementMethod(LinkMovementMethod.getInstance());

	itemView.setOnClickListener(new OnClickListener() {
		@Override public void onClick(View v) {
			Context context = v.getContext();
			Intent intent = null;
			if (boundInfo.isActivity()) {
				intent = new Intent(context.getApplicationContext(), boundInfo.getEntryClass());
			} else if (boundInfo.isFragment()) {
				intent = new Intent(context.getApplicationContext(), IssueFragmentActivity.class);
				intent.putExtra(IssueFragmentActivity.CONTENT_FRAGMENT, boundInfo.getEntryClass().getName());
			}
			if (intent == null) {
				Toast.makeText(context, "Cannot start " + boundInfo.getEntryClass(), Toast.LENGTH_LONG).show();
				return;
			}
			new GlideReset(context).replace(boundInfo.getModules());
			Log.d("SYS", "Starting " + intent);
			context.startActivity(intent);
		}
	});
}
 
Example #19
Source File: ImageExtensions.java    From Android-WYSIWYG-Editor with Apache License 2.0 5 votes vote down vote up
private void showNextInputHint(int index) {
    View view = editorCore.getParentView().getChildAt(index);
    EditorType type = editorCore.getControlType(view);
    if (type != EditorType.INPUT)
        return;
    TextView tv = (TextView) view;
    tv.setHint(editorCore.getPlaceHolder());
    Linkify.addLinks(tv,Linkify.ALL);
}
 
Example #20
Source File: Views.java    From Android-Shortify with Apache License 2.0 5 votes vote down vote up
public static $ linkify(){
    try{
        if(mView instanceof TextView){
            TextView textView = (TextView) mView;
            Linkify.addLinks(textView, Linkify.ALL);
        }
    }catch (Exception e){
        Log.d(TAG, e.getMessage());
    }
    return  $.getInstance();
}
 
Example #21
Source File: Splash.java    From Androzic with GNU General Public License v3.0 5 votes vote down vote up
private void showEula()
{
	final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
	boolean hasBeenShown = prefs.getBoolean(getString(R.string.app_eulaaccepted), false);
	if (hasBeenShown == false)
	{
		final SpannableString message = new SpannableString(Html.fromHtml(getString(R.string.app_eula).replace("/n", "<br/>")));
		Linkify.addLinks(message, Linkify.WEB_URLS);

		AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(getString(R.string.app_name)).setIcon(R.drawable.icon).setMessage(message)
				.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialogInterface, int i)
					{
						prefs.edit().putBoolean(getString(R.string.app_eulaaccepted), true).commit();
						wait = false;
						dialogInterface.dismiss();
					}
				}).setOnKeyListener(new OnKeyListener() {
					@Override
					public boolean onKey(DialogInterface dialoginterface, int keyCode, KeyEvent event)
					{
						return !(keyCode == KeyEvent.KEYCODE_HOME);
					}
				}).setCancelable(false);

		AlertDialog d = builder.create();

		d.show();
		// Make the textview clickable. Must be called after show()
		((TextView) d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
	}
	else
	{
		wait = false;
	}
}
 
Example #22
Source File: ConversationItem.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
private SpannableString linkifyMessageBody(SpannableString messageBody, boolean shouldLinkifyAllLinks) {
  boolean hasLinks = Linkify.addLinks(messageBody,
      shouldLinkifyAllLinks ? Linkify.EMAIL_ADDRESSES|Linkify.WEB_URLS|Linkify.PHONE_NUMBERS : 0);

  if (hasLinks) {
    URLSpan[] urlSpans = messageBody.getSpans(0, messageBody.length(), URLSpan.class);
    for (URLSpan urlSpan : urlSpans) {
      int start = messageBody.getSpanStart(urlSpan);
      int end = messageBody.getSpanEnd(urlSpan);
      messageBody.setSpan(new LongClickCopySpan(urlSpan.getURL()), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
  }
  return messageBody;
}
 
Example #23
Source File: MyLinkify.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
public static void addLinks(Editable body, boolean includeGeo) {
    Linkify.addLinks(body, Patterns.XMPP_PATTERN, "xmpp", XMPPURI_MATCH_FILTER, null);
    Linkify.addLinks(body, Patterns.AUTOLINK_WEB_URL, "http", WEBURL_MATCH_FILTER, WEBURL_TRANSFORM_FILTER);
    if (includeGeo) {
        Linkify.addLinks(body, GeoHelper.GEO_URI, "geo");
    }
    FixedURLSpan.fix(body);
}
 
Example #24
Source File: PatternUtils.java    From xifan with Apache License 2.0 5 votes vote down vote up
private static void linkifyUrl(Spannable spannable) {
    Linkify.TransformFilter transformFilter = new Linkify.TransformFilter() {
        @Override
        public String transformUrl(Matcher matcher, String value) {
            return value;
        }
    };
    Linkify.addLinks(spannable, PATTERN_URL, SCHEME_URL, null, transformFilter);
}
 
Example #25
Source File: ShowLinks.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
   TextView view =  (TextView) findViewById(R.id.textview);
   Linkify.addLinks(view, Linkify.WEB_URLS| Linkify.EMAIL_ADDRESSES);
}
 
Example #26
Source File: GeneralDetails.java    From YalpStore with GNU General Public License v2.0 5 votes vote down vote up
private void addOfferItem(String key, String value) {
    if (null == value) {
        return;
    }
    TextView itemView = new TextView(activity);
    try {
        itemView.setAutoLinkMask(Linkify.EMAIL_ADDRESSES | Linkify.WEB_URLS);
    } catch (RuntimeException e) {
        Log.w(getClass().getSimpleName(), "System WebView missing: " + e.getMessage());
        itemView.setAutoLinkMask(0);
    } finally {
        itemView.setText(activity.getString(R.string.two_items, key, Html.fromHtml(value)));
    }
    ((LinearLayout) activity.findViewById(R.id.offer_details)).addView(itemView);
}
 
Example #27
Source File: AdditTextActivity.java    From Quran-For-My-Android with Apache License 2.0 5 votes vote down vote up
private void updateNoOfFilesTextView() {
	
	if(FileItemContainer.getFileItems().size()!=0){
       	noOfFilesTextView.setText("Previously Added "+
       Integer.toString(FileItemContainer.getFileItems().size())+" file(s).\n"
       		+ "See \'Help\' to get suggestion about adding more files.");
       }else{
       	noOfFilesTextView.setText("No file added. Click \'"+getString(R.string.txt_but_addAdditText)
       			+"\' and select your downloaded/previously stored file (of .txt or .zip format).\nIf the file is not in your local storage"
       			+ " you may download it from here: http://zekr.org/resources.html#translation"
       			+ "\nDisclaimer: Their authenticity and/or accuracy is not guaranteed. Please use them at your own risk.");
       	Linkify.addLinks(noOfFilesTextView, Linkify.WEB_URLS);
       }
}
 
Example #28
Source File: LinkifyHelper.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
public static void addLinks(TextView text, SpanConverter<URLSpan, ClickableSpan> converter) {
    Linkify.addLinks(text, Linkify.WEB_URLS);
    Linkify.addLinks(text, geo, null);
    Linkify.addLinks(text, market, null);
    Linkify.addLinks(text, openpgp4fpr, null);
    Linkify.addLinks(text, xmpp, null);
    Linkify.addLinks(text, twitterHandle, "https://twitter.com/", null, returnMatchFilter);
    Linkify.addLinks(text, hashtag, "https://twitter.com/hashtag/", null, returnMatchFilter);
    text.setText(replaceAll(text.getText(), URLSpan.class, converter));
}
 
Example #29
Source File: SubscriptionsBackupsManager.java    From SkyTube with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A dialog that asks the user to import subscriptions from a YouTube account.
 */
public void displayImportSubscriptionsFromYouTubeDialog() {
	SpannableString msg = new SpannableString(activity.getText(R.string.import_subscriptions_description));
	Linkify.addLinks(msg, Linkify.WEB_URLS);
	new SkyTubeMaterialDialog(activity)
			.title(R.string.import_subscriptions)
			.content(msg)
			.positiveText(R.string.select_xml_file)
			.checkBoxPromptRes(R.string.unsubscribe_from_all_current_sibbed_channels, false, (compoundButton, b) -> isUnsubsribeAllChecked = true)
			.onPositive((dialog, which) -> displayFilePicker(false))
			.build()
			.show();
}
 
Example #30
Source File: AboutActivity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
private TextView createHtmlText(final String s, final int margin) {
    TextView text = new TextView(this);
    text.setAutoLinkMask(Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES);
    text.setText(Html.fromHtml(s));
    LinearLayout.LayoutParams layoutParams =
            new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
    int marginPx = (0 < margin) ? (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, margin,
            getResources().getDisplayMetrics()) : 0;
    layoutParams.setMargins(0, marginPx, 0, marginPx);
    text.setLayoutParams(layoutParams);
    return text;
}