Java Code Examples for android.widget.TextView#setAutoLinkMask()

The following examples show how to use android.widget.TextView#setAutoLinkMask() . 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: HelpFragment.java    From CapturePacket with MIT License 6 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    Toolbar toolbar =  view.findViewById(R.id.tool_bar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            FragmentActivity activity = getActivity();
            if (activity != null) {
                activity.getSupportFragmentManager()
                        .popBackStackImmediate();
            }
        }
    });
    TextView textView = view.findViewById(R.id.tv_content);
    textView.setAutoLinkMask(Linkify.WEB_URLS);
    textView.setLinkTextColor(0xffFF4081);
    textView.setLinksClickable(true);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
}
 
Example 2
Source File: MessageViewHolder.java    From zom-android-matrix with Apache License 2.0 6 votes vote down vote up
public MessageViewHolder(View view) {
    super(view);

    mTextViewForMessages = (TextView) view.findViewById(R.id.message);
    mTextViewForTimestamp = (TextView) view.findViewById(R.id.messagets);
    mAvatar = (ImageView) view.findViewById(R.id.avatar);
    mMediaContainer = (ViewGroup)view.findViewById(R.id.media_thumbnail_container);
    mAudioContainer = (ViewGroup)view.findViewById(R.id.audio_container);
   // mVisualizerView = (VisualizerView) view.findViewById(R.id.audio_view);
   // mAudioButton = (ImageView) view.findViewById(R.id.audio_button);

    // disable built-in autoLink so we can add custom ones
    if (mTextViewForMessages != null) {
        mTextViewForMessages.setAutoLinkMask(0);
    }
    //mContainer.setBackgroundResource(R.drawable.message_view_rounded_light);
}
 
Example 3
Source File: SubmitLogFragment.java    From libpastelog with GNU General Public License v3.0 6 votes vote down vote up
private TextView handleBuildSuccessTextView(final String logUrl) {
  TextView showText = new TextView(getActivity());

  showText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
  showText.setPadding(15, 30, 15, 30);
  showText.setText(getString(R.string.log_submit_activity__copy_this_url_and_add_it_to_your_issue, logUrl));
  showText.setAutoLinkMask(Activity.RESULT_OK);
  showText.setMovementMethod(LinkMovementMethod.getInstance());
  showText.setOnLongClickListener(new View.OnLongClickListener() {

    @Override
    public boolean onLongClick(View v) {
      @SuppressWarnings("deprecation")
      ClipboardManager manager =
          (ClipboardManager) getActivity().getSystemService(Activity.CLIPBOARD_SERVICE);
      manager.setText(logUrl);
      Toast.makeText(getActivity(),
                     R.string.log_submit_activity__copied_to_clipboard,
                     Toast.LENGTH_SHORT).show();
      return true;
    }
  });

  Linkify.addLinks(showText, Linkify.WEB_URLS);
  return showText;
}
 
Example 4
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 5
Source File: PhysicalWebDiagnosticsPage.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
protected void initialize(final Activity activity, Tab tab) {
    Resources resources = activity.getResources();
    mSuccessColor = colorToHexValue(ApiCompatibilityUtils.getColor(resources,
            R.color.physical_web_diags_success_color));
    mFailureColor = colorToHexValue(ApiCompatibilityUtils.getColor(resources,
            R.color.physical_web_diags_failure_color));
    mIndeterminateColor = colorToHexValue(ApiCompatibilityUtils.getColor(resources,
            R.color.physical_web_diags_indeterminate_color));

    LayoutInflater inflater = LayoutInflater.from(activity);
    mPageView = inflater.inflate(R.layout.physical_web_diagnostics, null);

    mLaunchButton = (Button) mPageView.findViewById(R.id.physical_web_launch);
    mLaunchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            activity.startActivity(createListUrlsIntent());
        }
    });

    mDiagnosticsText = (TextView) mPageView.findViewById(R.id.physical_web_diagnostics_text);
    mDiagnosticsText.setAutoLinkMask(Linkify.WEB_URLS);
    mDiagnosticsText.setText(Html.fromHtml(createDiagnosticsReportHtml()));
}
 
Example 6
Source File: AboutFragment.java    From easyweather with MIT License 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    getActivity().setTheme(R.style.DayTheme);
    if (MyApplication.nightMode2()) {
        initNightView(R.layout.night_mode_overlay);
    }

    View view = inflater.inflate(R.layout.fragment_about, container, false);
    TextView tv = (TextView) view.findViewById(R.id.link);
    String textStr = "https://github.com/byhieg/easyweather";
    tv.setAutoLinkMask(Linkify.WEB_URLS);
    tv.setText(textStr);
    Spannable s = (Spannable) tv.getText();
    s.setSpan(new UnderlineSpan() {
        @Override
        public void updateDrawState(TextPaint ds) {
            ds.setColor(ds.linkColor);
            ds.setUnderlineText(false);
        }
    }, 0, textStr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return view;
}
 
Example 7
Source File: DiscussionTextUtils.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
/**
 * Renders various HTML elements and plain hyperlinks in the given HTML to clickable items
 * while applying it on the given {@link TextView}.
 *
 * @param textView The {@link TextView} which will render the given HTML.
 * @param html     The HTML to render.
 */
public static void renderHtml(@NonNull TextView textView, @NonNull String html) {
    Spanned spannedHtml = DiscussionTextUtils.parseHtml(html);
    URLSpan[] urlSpans = spannedHtml.getSpans(0, spannedHtml.length(), URLSpan.class);
    textView.setAutoLinkMask(Linkify.ALL);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    textView.setText(spannedHtml);

    SpannableString viewText = (SpannableString) textView.getText();
    for (final URLSpan spanObj : urlSpans) {
        final int start = spannedHtml.getSpanStart(spanObj);
        final int end = spannedHtml.getSpanEnd(spanObj);
        final int flags = spannedHtml.getSpanFlags(spanObj);
        viewText.setSpan(spanObj, start, end, flags);
    }
}
 
Example 8
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 9
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;
}
 
Example 10
Source File: AboutActivity.java    From UltimateAndroid 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;
}
 
Example 11
Source File: AboutIt.java    From AboutIt with Apache License 2.0 5 votes vote down vote up
/**
 * Generate text and put in @ref{about_text}
 * @param about_text Resource it of destination TextView
 */
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
public void toTextView(@IdRes int about_text) {
    TextView out = (TextView) activity.findViewById(about_text);
    out.setAutoLinkMask(Linkify.WEB_URLS);

    endYear = endYear();

    StringBuilder sb = new StringBuilder();
    if (appName != null)
        sb.append(appName+" v"+getVersionString()+"\n");

    if (copyright != null) {
        sb.append("Copyright (c) ");
        if (year != 0)
            sb.append(year + (endYear != 0 ? " - " + endYear : "") + " ");
        sb.append(copyright + "\n\n");
    }

    if (description != null)
        sb.append(description+"\n\n");

    // Sort library list alphabetically by name
    Collections.sort(libs, new Comparator<Lib>() {
        @Override
        public int compare(Lib lhs, Lib rhs) {
            return lhs.name.compareTo(rhs.name);
        }
    });

    for(Lib l:libs){
        sb.append(l.byLine() + "\n");
    }

    out.setText(sb.toString());
}
 
Example 12
Source File: OpenAdapter.java    From MaterialQQLite with Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = inflater.inflate(
                R.layout.open_listitem, null);
    }
    TextView link = (TextView) convertView.findViewById(R.id.open_list_item_link);
    link.setAutoLinkMask(Linkify.WEB_URLS);
    switch (position){
        case 0:
            link.setText("https://github.com/zym2014/MingQQ");
            break;
        case 1:
            link.setText("https://github.com/neokree/MaterialTabs");
            break;
        case 2:
            link.setText("https://github.com/afollestad/material-dialogs");
            break;
        case 3:
            link.setText("https://github.com/kyleduo/SwitchButton");
            break;
        case 4:
            link.setText("https://github.com/keithellis/MaterialWidget");
            break;
        case 5:
            link.setText("https://github.com/baoyongzhang/android-PullRefreshLayout");
            break;
        case 6:
            link.setText("https://github.com/ikew0ng/SwipeBackLayout");
            break;
        case 7:
            link.setText("https://github.com/wang4yu6peng13/MaterialQQLite");
            break;
    }

    TextView text = (TextView) convertView.findViewById(R.id.open_list_item); //设置条目的文字说明
    text.setText(open_list.get(position));
    return convertView;
}
 
Example 13
Source File: PhysicalWebDiagnosticsPage.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("deprecation") // Update usage of Html.fromHtml when API min is 24
protected void initialize(final Activity activity, NativePageHost host) {
    Resources resources = activity.getResources();
    mSuccessColor = colorToHexValue(ApiCompatibilityUtils.getColor(resources,
            R.color.physical_web_diags_success_color));
    mFailureColor = colorToHexValue(ApiCompatibilityUtils.getColor(resources,
            R.color.physical_web_diags_failure_color));
    mIndeterminateColor = colorToHexValue(ApiCompatibilityUtils.getColor(resources,
            R.color.physical_web_diags_indeterminate_color));

    LayoutInflater inflater = LayoutInflater.from(activity);
    mPageView = inflater.inflate(R.layout.physical_web_diagnostics, null);

    mLaunchButton = (Button) mPageView.findViewById(R.id.physical_web_launch);
    mLaunchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PhysicalWebUma.onActivityReferral(PhysicalWebUma.DIAGNOSTICS_REFERER);
            PhysicalWeb.showUrlList();
        }
    });

    mDiagnosticsText = (TextView) mPageView.findViewById(R.id.physical_web_diagnostics_text);
    mDiagnosticsText.setAutoLinkMask(Linkify.WEB_URLS);
    mDiagnosticsText.setText(Html.fromHtml(createDiagnosticsReportHtml()));
}
 
Example 14
Source File: AboutIt.java    From AboutIt with Apache License 2.0 5 votes vote down vote up
/**
 * Generate text and put in @ref{about_text}
 * @param about_text Resource it of destination TextView
 */
@SuppressWarnings("StringConcatenationInsideStringBufferAppend")
public void toTextView(@IdRes int about_text) {
    TextView out = (TextView) activity.findViewById(about_text);
    out.setAutoLinkMask(Linkify.WEB_URLS);

    endYear = endYear();

    StringBuilder sb = new StringBuilder();
    if (appName != null)
        sb.append(appName+" v"+getVersionString()+"\n");

    if (copyright != null) {
        sb.append("Copyright (c) ");
        if (year != 0)
            sb.append(year + (endYear != 0 ? " - " + endYear : "") + " ");
        sb.append(copyright + "\n\n");
    }

    if (description != null)
        sb.append(description+"\n\n");

    // Sort library list alphabetically by name
    Collections.sort(libs, new Comparator<Lib>() {
        @Override
        public int compare(Lib lhs, Lib rhs) {
            return lhs.name.compareTo(rhs.name);
        }
    });

    for(Lib l:libs){
        sb.append(l.byLine() + "\n");
    }

    out.setText(sb.toString());
}
 
Example 15
Source File: Objective.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
public TextView generate(Context context) {
    TextView textView = new TextView(context);
    textView.setText(hint);
    textView.setAutoLinkMask(Linkify.WEB_URLS);
    textView.setLinksClickable(true);
    textView.setLinkTextColor(Color.YELLOW);
    Linkify.addLinks(textView, Linkify.WEB_URLS);
    return textView;
}
 
Example 16
Source File: SWHtmlLink.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void generateDialog(LinearLayout layout) {
    Context context = layout.getContext();

    l = new TextView(context);
    l.setId(View.generateViewId());
    l.setAutoLinkMask(Linkify.ALL);
    if(textLabel != null)
        l.setText(textLabel);
    else
        l.setText(label);
    layout.addView(l);

}
 
Example 17
Source File: PhysicalWebDiagnosticsPage.java    From delion with Apache License 2.0 5 votes vote down vote up
public PhysicalWebDiagnosticsPage(Context context) {
    mContext = context;

    Resources resources = mContext.getResources();
    mBackgroundColor = ApiCompatibilityUtils.getColor(resources, R.color.ntp_bg);
    mThemeColor = ApiCompatibilityUtils.getColor(resources, R.color.default_primary_color);
    mSuccessColor = colorToHexValue(ApiCompatibilityUtils.getColor(resources,
            R.color.physical_web_diags_success_color));
    mFailureColor = colorToHexValue(ApiCompatibilityUtils.getColor(resources,
            R.color.physical_web_diags_failure_color));
    mIndeterminateColor = colorToHexValue(ApiCompatibilityUtils.getColor(resources,
            R.color.physical_web_diags_indeterminate_color));

    LayoutInflater inflater = LayoutInflater.from(mContext);
    mPageView = inflater.inflate(R.layout.physical_web_diagnostics, null);

    mLaunchButton = (Button) mPageView.findViewById(R.id.physical_web_launch);
    mLaunchButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mContext.startActivity(createListUrlsIntent(mContext));
        }
    });

    mDiagnosticsText = (TextView) mPageView.findViewById(R.id.physical_web_diagnostics_text);
    mDiagnosticsText.setAutoLinkMask(Linkify.WEB_URLS);
    mDiagnosticsText.setText(Html.fromHtml(createDiagnosticsReportHtml()));
}
 
Example 18
Source File: SubAssignmentsAdapter.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
private void convertBody(BaseViewHolder helper, SubAssignment subAssignment) {
    SubAssignmentType subAssignmentType = subAssignment.getSubAssignmentType();
    boolean showIcon = subAssignmentType == SubAssignmentType.TODO
            || subAssignmentType == SubAssignmentType.NOTE_WITH_PORTRAIT;

    helper.addOnClickListener(R.id.tv_sub_assignment);
    helper.addOnClickListener(R.id.iv_sub_assignment);
    helper.addOnClickListener(R.id.tv_sub_assignment_note);

    helper.getView(R.id.tv_sub_assignment).setVisibility(showIcon ? View.VISIBLE : View.GONE);
    helper.getView(R.id.iv_sub_assignment).setVisibility(showIcon ? View.VISIBLE : View.GONE);
    helper.getView(R.id.tv_sub_assignment_note).setVisibility(showIcon ? View.GONE : View.VISIBLE);
    helper.getView(R.id.divider_note).setVisibility(showIcon ? View.GONE : View.VISIBLE);
    helper.getView(R.id.divider_todo).setVisibility(showIcon ? View.VISIBLE : View.GONE);

    TextView tvSub = helper.getView(R.id.tv_sub_assignment);
    tvSub.setText(subAssignment.getContent());
    tvSub.setAutoLinkMask(Linkify.ALL);
    tvSub.setMovementMethod(LinkMovementMethod.getInstance());
    tvSub.setPaintFlags(subAssignment.isCompleted() ? tvSub.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG : tvSub.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
    ViewUtils.setAlpha(tvSub, subAssignment.isCompleted() ? 0.4F : 1F);

    helper.setImageDrawable(R.id.iv_sub_assignment,
            ColorUtils.tintDrawable(PalmApp.getDrawableCompact(
                    subAssignmentType == SubAssignmentType.TODO ?
                            subAssignment.isCompleted() ?
                                    R.drawable.ic_check_box_black_24dp :
                                    R.drawable.ic_check_box_outline_blank_black_24dp :
                            subAssignment.getPortrait().iconRes), ColorUtils.accentColor()));

    helper.setText(R.id.tv_sub_assignment_note, subAssignment.getContent());
}
 
Example 19
Source File: Linker.java    From SkyTube with GNU General Public License v3.0 4 votes vote down vote up
public static void configure(TextView textView) {
	textView.setAutoLinkMask(0);
	textView.setMovementMethod(new TouchableMovementMethod(new LinkListener(textView.getContext())));
}
 
Example 20
Source File: BetterLinkMovementExtended.java    From mvvm-template with GNU General Public License v3.0 4 votes vote down vote up
public boolean onTouchEvent(TextView view, Spannable text, MotionEvent event) {
    if (this.activeTextViewHashcode != view.hashCode()) {
        this.activeTextViewHashcode = view.hashCode();
        view.setAutoLinkMask(0);
    }

    BetterLinkMovementExtended.ClickableSpanWithText touchedClickableSpan = this.findClickableSpanUnderTouch(view, text, event);
    if (touchedClickableSpan != null) {
        this.highlightUrl(view, touchedClickableSpan, text);
    } else {
        this.removeUrlHighlightColor(view);
    }

    clickGestureListener.listener = new GestureDetector.SimpleOnGestureListener() {
        @Override public boolean onDown(MotionEvent e) {
            touchStartedOverLink = touchedClickableSpan != null;
            return true;
        }

        @Override public boolean onSingleTapUp(MotionEvent e) {
            if (touchedClickableSpan != null && touchStartedOverLink) {
                dispatchUrlClick(view, touchedClickableSpan);
                removeUrlHighlightColor(view);
            }

            touchStartedOverLink = false;
            return true;
        }

        @Override public void onLongPress(MotionEvent e) {
            if (touchedClickableSpan != null && touchStartedOverLink) {
                dispatchUrlLongClick(view, touchedClickableSpan);
                removeUrlHighlightColor(view);
            }

            touchStartedOverLink = false;
        }
    };

    boolean ret = gestureDetector.onTouchEvent(event);

    if(!ret && event.getAction() == MotionEvent.ACTION_UP) {
        clickGestureListener.listener = null;
        removeUrlHighlightColor(view);
        this.touchStartedOverLink = false;
        ret = true;
    }

    return ret;
}