Java Code Examples for android.text.util.Linkify#addLinks()

The following examples show how to use android.text.util.Linkify#addLinks() . 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: PoiDetailsFragment.java    From AndroidApp with Mozilla Public License 2.0 6 votes vote down vote up
private View inflateRowItem(String title, String value) {
    View view;
    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    view = inflater.inflate(R.layout.detailed_poi_tagitem, null);

    //LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.rowContainer);
    TextView titleTextView = (TextView) view.findViewById(R.id.rowTitle);
    TextView valueTextView = (TextView) view.findViewById(R.id.rowValue);
    titleTextView.setText(title);
    valueTextView.setText(value);
    //Linking content
    if (title.toLowerCase().equals("email") || title.toLowerCase().equals("contact:email")) {
        Linkify.addLinks(valueTextView, Linkify.EMAIL_ADDRESSES);
        valueTextView.setLinksClickable(true);
    }
    if (title.toLowerCase().equals("website") || title.toLowerCase().equals("contact:website")) {
        Linkify.addLinks(valueTextView, Linkify.WEB_URLS);
        valueTextView.setLinksClickable(true);
    }
    if (title.toLowerCase().equals("phone") || title.toLowerCase().equals("phone:mobile") || title.toLowerCase().equals("contact:mobile") || title.toLowerCase().equals("contact:phone")) {
        Linkify.addLinks(valueTextView, Linkify.PHONE_NUMBERS);
        valueTextView.setLinksClickable(true);
    }
    return view;
}
 
Example 2
Source File: AboutUsFragment.java    From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private SpannableString getDescriptionMessage(Context context) {
    InputStream message = context.getResources().openRawResource(R.raw.description);
    String stringMessage = convertFromInputStreamToString(message).toString();
    final SpannableString linkedMessage = new SpannableString(Html.fromHtml(stringMessage));
    Linkify.addLinks(linkedMessage, Linkify.EMAIL_ADDRESSES | Linkify.WEB_URLS);
    return linkedMessage;
}
 
Example 3
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 4
Source File: SampleDialogFragment.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 5
Source File: CodecsFragment.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
private void userActivateCodec(final Map<String, Object> codec, boolean activate) {
    
    String codecName = (String) codec.get(CODEC_ID);
    final short newPrio = activate ? (short) 1 : (short) 0;

    boolean isDisabled = ((Short) codec.get(CODEC_PRIORITY) == 0);
    if(isDisabled == !activate) {
        // Nothing to do, this codec is already enabled
        return;
    }
    
    if(NON_FREE_CODECS.containsKey(codecName) && activate) {

        final TextView message = new TextView(getActivity());
        final SpannableString s = new SpannableString(getString(R.string.this_codec_is_not_free) + NON_FREE_CODECS.get(codecName));
        Linkify.addLinks(s, Linkify.WEB_URLS);
        message.setText(s);
        message.setMovementMethod(LinkMovementMethod.getInstance());
        message.setPadding(10, 10, 10, 10);
          
        
        //Alert user that we will disable for all incoming calls as he want to quit
        new AlertDialog.Builder(getActivity())
            .setTitle(R.string.warning)
            .setView(message)
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    setCodecActivated(codec, newPrio);
                }
            })
            .setNegativeButton(R.string.cancel, null)
            .show();
    }else {
        setCodecActivated(codec, newPrio);
    }
}
 
Example 6
Source File: SimpleTest.java    From unmock-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testSpannable() {
    final Spannable text = new SpannableString("Test http://www.test.de !");
    Linkify.addLinks(text, Linkify.WEB_URLS);
    assertEquals(
            "<p dir=\"ltr\">Test <a href=\"http://www.test.de\">http://www.test.de</a> !</p>\n",
            Html.toHtml(text));
}
 
Example 7
Source File: ProviderCredentialsBaseActivity.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
private void handleReceivedErrors(Bundle arguments) {
    if (arguments.containsKey(CREDENTIAL_ERRORS.PASSWORD_INVALID_LENGTH.toString())) {
        updatePasswordError(getString(R.string.error_not_valid_password_user_message));
    } else if (arguments.containsKey(CREDENTIAL_ERRORS.RISEUP_WARNING.toString())) {
        userMessage.setVisibility(VISIBLE);
        userMessage.setText(R.string.login_riseup_warning);
    }
    if (arguments.containsKey(CREDENTIALS_USERNAME)) {
        String username = arguments.getString(CREDENTIALS_USERNAME);
        usernameField.setText(username);
    }
    if (arguments.containsKey(CREDENTIAL_ERRORS.USERNAME_MISSING.toString())) {
        updateUsernameError(getString(R.string.username_ask));
    }
    if (arguments.containsKey(USER_MESSAGE)) {
        String userMessageString = arguments.getString(USER_MESSAGE);
        try {
             userMessageString = new JSONArray(userMessageString).getString(0);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        if (Build.VERSION.SDK_INT >= VERSION_CODES.N) {
            userMessage.setText(Html.fromHtml(userMessageString, Html.FROM_HTML_MODE_LEGACY));
        } else {
            userMessage.setText(Html.fromHtml(userMessageString));
        }
        Linkify.addLinks(userMessage, Linkify.ALL);
        userMessage.setMovementMethod(LinkMovementMethod.getInstance());
        userMessage.setVisibility(VISIBLE);
    } else if (userMessage.getVisibility() != GONE) {
        userMessage.setVisibility(GONE);
    }

    if (!usernameField.getText().toString().isEmpty() && passwordField.isFocusable())
        passwordField.requestFocus();

    mConfigState.setAction(SHOWING_FORM);
    hideProgressBar();
}
 
Example 8
Source File: MainActivity.java    From TinyList with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Just info about the app :-)
 */
private void showAboutDialog() {
    final SpannableString spannableString = new SpannableString(getString(R.string.about_msg));
    Linkify.addLinks(spannableString, Linkify.ALL);

    new MaterialDialog.Builder(this)
            .positiveText(android.R.string.ok)
            .title(getString(R.string.app_name) + " " + getString(R.string.app_version))
            .content(spannableString)
            .show();
}
 
Example 9
Source File: LongMessageActivity.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private SpannableString linkifyMessageBody(SpannableString messageBody) {
  int     linkPattern = Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES | Linkify.PHONE_NUMBERS;
  boolean hasLinks    = Linkify.addLinks(messageBody, linkPattern);

  if (hasLinks) {
    Stream.of(messageBody.getSpans(0, messageBody.length(), URLSpan.class))
          .filterNot(url -> LinkPreviewUtil.isLegalUrl(url.getURL()))
          .forEach(messageBody::removeSpan);
  }
  return messageBody;
}
 
Example 10
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 11
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 12
Source File: MartianViewHolder.java    From RxJava2RetrofitDemo with Apache License 2.0 4 votes vote down vote up
@Override
public MartianViewHolder linkify(int viewId) {
    TextView view = getView(viewId);
    Linkify.addLinks(view, Linkify.ALL);
    return this;
}
 
Example 13
Source File: ViewHolder.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ViewHolder linkify(int viewId)
{
    TextView view = getView(viewId);
    Linkify.addLinks(view, Linkify.ALL);
    return this;
}
 
Example 14
Source File: XViewHolder.java    From XFrame with Apache License 2.0 4 votes vote down vote up
public XViewHolder linkify(@IdRes int viewId) {
    TextView view = getView(viewId);
    Linkify.addLinks(view, Linkify.ALL);
    return this;
}
 
Example 15
Source File: ViewHolder.java    From SmartChart with Apache License 2.0 4 votes vote down vote up
public ViewHolder linkify(int viewId) {
    TextView view = getView(viewId);
    Linkify.addLinks(view, Linkify.ALL);
    return this;
}
 
Example 16
Source File: ViewHolder.java    From baseAdapter with Apache License 2.0 4 votes vote down vote up
public ViewHolder linkify(int viewId)
{
    TextView view = getView(viewId);
    Linkify.addLinks(view, Linkify.ALL);
    return this;
}
 
Example 17
Source File: BaseRecyclerHolder.java    From CoordinatorLayoutExample with Apache License 2.0 4 votes vote down vote up
public BaseRecyclerHolder linkify(int viewId) {
    TextView view = getView(viewId);
    Linkify.addLinks(view, Linkify.ALL);
    return this;
}
 
Example 18
Source File: ViewHolder.java    From all-base-adapter with Apache License 2.0 4 votes vote down vote up
public ViewHolder linkify(int viewId) {
    TextView view = getView(viewId);
    Linkify.addLinks(view, Linkify.ALL);
    return this;
}
 
Example 19
Source File: RecyclerViewHolder.java    From LRecyclerView with Apache License 2.0 4 votes vote down vote up
public RecyclerViewHolder linkify(int viewId) {
    TextView view = findViewById(viewId);
    Linkify.addLinks(view, Linkify.ALL);
    return this;
}
 
Example 20
Source File: BaseViewHolder.java    From AndroidBase with Apache License 2.0 2 votes vote down vote up
/**
 * Add links into a TextView.
 *
 * @param viewId The id of the TextView to linkify.
 * @return The BaseViewHolder for chaining.
 */
public BaseViewHolder linkify(int viewId) {
    TextView view = getView(viewId);
    Linkify.addLinks(view, Linkify.ALL);
    return this;
}