项目:Forge
文件:GeneratorFragment.java
/**
* Taken from Stack Overflow - https://stackoverflow.com/a/17201376/6052295
* Adds links to a HTML string
*
* @param html the HTML string to add links to
* @param linkifyMask the link type
* @return The spannable text with clickable links
*/
public static Spannable linkifyHtml(String html,int linkifyMask) {
Spanned text = fromHtml(fromHtml(html).toString());
URLSpan[] currentSpans = text.getSpans(0,text.length(),URLSpan.class);
SpannableString buffer = new SpannableString(text);
Linkify.addLinks(buffer,linkifyMask);
for (URLSpan span : currentSpans) {
int end = text.getSpanEnd(span);
int start = text.getSpanStart(span);
buffer.setSpan(span,start,end,0);
}
return buffer;
}
项目:ultrasonic
文件:ShareActivity.java
private void displayShareInfo(final Share share)
{
final TextView textView = new TextView(this);
textView.setPadding(5,5,5);
final Spannable message = new SpannableString("Owner: " + share.getUsername() +
"\nComments: " + ((share.getDescription() == null) ? "" : share.getDescription()) +
"\nURL: " + share.getUrl() +
"\nEntry Count: " + share.getEntries().size() +
"\nVisit Count: " + share.getVisitCount() +
((share.getCreated() == null) ? "" : ("\nCreation Date: " + share.getCreated().replace('T',' '))) +
((share.getLastVisited() == null) ? "" : ("\nLast Visited Date: " + share.getLastVisited().replace('T',' '))) +
((share.getExpires() == null) ? "" : ("\nExpiration Date: " + share.getExpires().replace('T',' '))));
Linkify.addLinks(message,Linkify.WEB_URLS);
textView.setText(message);
textView.setMovementMethod(LinkMovementMethod.getInstance());
new AlertDialog.Builder(this).setTitle("Share Details").setCancelable(true).setIcon(android.R.drawable.ic_dialog_info).setView(textView).show();
}
项目:ultrasonic
文件:SelectPlaylistActivity.java
private void displayPlaylistInfo(final Playlist playlist)
{
final TextView textView = new TextView(this);
textView.setPadding(5,5);
final Spannable message = new SpannableString("Owner: " + playlist.getowner() + "\nComments: " +
((playlist.getComment() == null) ? "" : playlist.getComment()) +
"\nSong Count: " + playlist.getSongCount() +
((playlist.getPublic() == null) ? "" : ("\nPublic: " + playlist.getPublic()) + ((playlist.getCreated() == null) ? "" : ("\nCreation Date: " + playlist.getCreated().replace('T',' ')))));
Linkify.addLinks(message,Linkify.WEB_URLS);
textView.setText(message);
textView.setMovementMethod(LinkMovementMethod.getInstance());
new AlertDialog.Builder(this).setTitle(playlist.getName()).setCancelable(true).setIcon(android.R.drawable.ic_dialog_info).setView(textView).show();
}
项目:yyox
文件:CustomTextView.java
/**
* 显示富文本消息
*
* @param textView
* @param message
*/
public static void setCustomMessage(TextView textView,String message) {
JSONObject jsonObject = SafeJson.parSEObj(message);
if (SafeJson.isContainKey(jsonObject,CustomField.TYPE)) {
String type = SafeJson.safeGet(jsonObject,CustomField.TYPE);
if (TextUtils.equals(CustomField.VIDEO,type)) {
if (SafeJson.isContainKey(jsonObject,CustomField.VISITOR_URL)) {
String url = SafeJson.safeGet(jsonObject,CustomField.VISITOR_URL);
textView.setText(makeUrlWithHtmlHref(url,textView.getContext().getString(R.string.kf5_invite_video_chat)));
} else {
textView.setText(resolveTextWithHtmlTag(message));
}
} else {
textView.setText(resolveTextWithHtmlTag(message));
}
} else {
textView.setText(resolveTextWithHtmlTag(message));
}
dealCustomLink(textView);
Linkify.addLinks(textView,Linkify.ALL);
textView.setMovementMethod(new CustomLinkMovementMethod());
dealCustomLink(textView);
}
项目:Android-Development
文件:PoiDetailsFragment.java
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;
}
项目:PeSanKita-android
文件:ConversationItem.java
private void setInteractionState(MessageRecord messageRecord) {
setSelected(batchSelected.contains(messageRecord));
bodyText.setAutoLinkMask(batchSelected.isEmpty() ? Linkify.ALL : 0);
if (mediaThumbnailStub.resolved()) {
mediaThumbnailStub.get().setFocusable(!shouldInterceptClicks(messageRecord) && batchSelected.isEmpty());
mediaThumbnailStub.get().setClickable(!shouldInterceptClicks(messageRecord) && batchSelected.isEmpty());
mediaThumbnailStub.get().setLongClickable(batchSelected.isEmpty());
}
if (audioViewStub.resolved()) {
audioViewStub.get().setFocusable(!shouldInterceptClicks(messageRecord) && batchSelected.isEmpty());
audioViewStub.get().setClickable(batchSelected.isEmpty());
audioViewStub.get().setEnabled(batchSelected.isEmpty());
}
}
项目:airgram
文件:MessageObject.java
public void generateLinkDescription() {
if (linkDescription != null) {
return;
}
if (messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && messageOwner.media.webpage instanceof TLRPC.TL_webPage && messageOwner.media.webpage.description != null) {
linkDescription = Spannable.Factory.getInstance().newSpannable(messageOwner.media.webpage.description);
if (containsUrls(linkDescription)) {
try {
Linkify.addLinks((Spannable) linkDescription,Linkify.WEB_URLS);
} catch (Exception e) {
FileLog.e("tmessages",e);
}
}
linkDescription = Emoji.replaceEmoji(linkDescription,textPaint.getFontMetricsInt(),AndroidUtilities.dp(20),false);
}
}
项目:airgram
文件:MessageObject.java
public void generateCaption() {
if (caption != null) {
return;
}
if (messageOwner.media != null && messageOwner.media.caption != null && messageOwner.media.caption.length() > 0) {
caption = Emoji.replaceEmoji(messageOwner.media.caption,false);
if (containsUrls(caption)) {
try {
Linkify.addLinks((Spannable) caption,Linkify.WEB_URLS | Linkify.PHONE_NUMBERS);
} catch (Exception e) {
FileLog.e("tmessages",e);
}
addUsernamesAndHashtags(caption,true);
}
}
}
项目:stay-awake-app
文件:MainActivity.java
private void formatMessages() {
// Add actual minutes to string template.
TextView textView1 = (TextView) findViewById(R.id.text_introduction_content);
final long hours = TimeUnit.SECONDS.toMinutes(MyTileService.MAX_TIME_SEC);
textView1.setText(getString(R.string.introduction_body,hours));
// Linkify github link.
TextView textview2 = (TextView) findViewById(R.id.text_opensource_body);
LinkifyCompat.addLinks(textview2,Linkify.WEB_URLS);
// Spanning color on textviews.
applySpan((TextView) findViewById(R.id.text_install_body_1),R.id.text_install_body_1,"Step 1");
applySpan((TextView) findViewById(R.id.text_install_body_2),R.id.text_install_body_2,"Step 2");
applySpan((TextView) findViewById(R.id.text_install_body_3),R.id.text_install_body_3,"Step 3");
}
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);
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();
}
项目:chromium-for-android-56-debug-video
文件:PhysicalWebDiagnosticsPage.java
@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()));
}
项目:xifan
文件:PatternUtils.java
private static void linkifyUsers(Spannable spannable,final Map<String,String> userMap) {
Linkify.MatchFilter filter = new Linkify.MatchFilter() {
@Override
public final boolean acceptMatch(final CharSequence s,final int start,final int end) {
String name = s.subSequence(start + 1,end).toString().trim();
return userMap.containsKey(name);
}
};
Linkify.TransformFilter transformFilter = new Linkify.TransformFilter() {
@Override
public String transformUrl(Matcher matcher,String value) {
String userName = value.subSequence(1,value.length()).toString().trim();
String userId = userMap.get(userName);
return userId;
}
};
Linkify.addLinks(spannable,PATTERN_AT,SCHEME_AT,filter,transformFilter);
}
项目:Obd2-Tracker
文件:GeneratedAccountIdDialog.java
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final TextView textView = new TextView(getActivity());
final SpannableString spannableMsg = new SpannableString("See your real time car data at page " + Config.WWW_APP_URL + "/pages/index.html?account=Todo");
Linkify.addLinks(spannableMsg,Linkify.WEB_URLS);
textView.setText(spannableMsg);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setPadding(20,20,20);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Your Account")
.setView(textView)
.setPositiveButton(android.R.string.ok,null);
return builder.create();
}
项目:PlusGram
文件:MessageObject.java
public void generateLinkDescription() {
if (linkDescription != null) {
return;
}
if (messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && messageOwner.media.webpage instanceof TLRPC.TL_webPage && messageOwner.media.webpage.description != null) {
linkDescription = Spannable.Factory.getInstance().newSpannable(messageOwner.media.webpage.description);
} else if (messageOwner.media instanceof TLRPC.TL_messageMediaGame && messageOwner.media.game.description != null) {
linkDescription = Spannable.Factory.getInstance().newSpannable(messageOwner.media.game.description);
}
if (linkDescription != null) {
if (containsUrls(linkDescription)) {
try {
Linkify.addLinks((Spannable) linkDescription,false);
}
}
项目:PlusGram
文件:MessageObject.java
public void generateCaption() {
if (caption != null) {
return;
}
if (messageOwner.media != null && messageOwner.media.caption != null && messageOwner.media.caption.length() > 0) {
caption = Emoji.replaceEmoji(messageOwner.media.caption,true);
}
}
}
项目:WeChatDemo
文件:LinkifyUtil.java
/**
* 添加自定义超链接
*/
public static void addCustomLink(TextView textView) {
// @用户:
Pattern pattern = Pattern.compile("\\@([A-Za-z0-9\u4E00-\u9FA5]+)\\.?");
// http://www.qq.com/path?uid=1&username=xx
String scheme = "weibo://user?uid=";
// 匹配过滤器
Linkify.MatchFilter matchFilter = new Linkify.MatchFilter() {
@Override
public boolean acceptMatch(CharSequence s,int start,int end) {
String text = s.subSequence(start,end).toString();
// System.out.println("----text: " + text);
if (text.endsWith(".")) { // 邮箱,不需要匹配
return false;
} else {
return true; // 返回true会显示为超链接
}
}
};
Linkify.TransformFilter transformFilter = null;
Linkify.addLinks(textView,pattern,scheme,matchFilter,transformFilter);
}
项目:WeChatDemo
文件:LinkifyUtil.java
public static void addCustomLink2(TextView textView) {
// @用户:
Pattern pattern = Pattern.compile("\\#([A-Za-z0-9\u4E00-\u9FA5]+)\\#");
// http://www.qq.com/path?uid=1&username=xx
String scheme = "weibo://topic?uid=";
// 匹配过滤器
Linkify.MatchFilter matchFilter = new Linkify.MatchFilter() {
@Override
public boolean acceptMatch(CharSequence s,end).toString();
System.out.println("----text: " + text);
return true;
}
};
Linkify.TransformFilter transformFilter = new Linkify.TransformFilter() {
@Override
public String transformUrl(Matcher match,String url) {
return match.group(1);
}
};
Linkify.addLinks(textView,transformFilter);
}
项目:Android_watch_magpie
文件:MainActivity.java
private void showAboutDialog() {
// Transform text into URL link
View aboutView = getLayoutInflater().inflate(R.layout.dialog_about,null,false);
TextView txtView = (TextView) aboutView.findViewById(R.id.aboutTxtView);
Pattern pattern = Pattern.compile("here");
Linkify.addLinks(txtView,getString(R.string.magpie_url));
// Create and show the dialog
AlertDialog.Builder builder = new AlertDialog.Builder(
new ContextThemeWrapper(
this,android.R.style.Theme_Material_Light_NoActionBar_Fullscreen));
builder.setTitle(getString(R.string.about_app))
.setView(aboutView)
.create()
.show();
}
项目:LibVNCAndroid
文件:ActivityTabs.java
/**
* @brief Shows the dialog to indicate about info
* @return The new dialog
* @details Shows the dialog to indicate about info
*/
private Dialog createAboutDialog()
{
//necesario para poder clicar en los links
final TextView message = new TextView(this);
final SpannableString s =
new SpannableString(this.getText(R.string.about_message));
Linkify.addLinks(s,Linkify.WEB_URLS);
message.setText(s);
message.setMovementMethod(LinkMovementMethod.getInstance());
return new AlertDialog.Builder(this)
.setTitle(R.string.about_title)
.setView(message)
.setPositiveButton(R.string.about_ok,new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
// Auto-generated method stub
}
}
)
.show();
}
项目:droidfan
文件:StatusUtils.java
public static void setStatus(final TextView textView,final String text) {
final String htmlText = text + " ";
// LogUtil.v(TAG,"setStatus:htmlText:" + htmlText);
final HashMap<String,String> mentions = findMentions(htmlText);
// LogUtil.v(TAG,"setStatus:mentions:" + mentions);
final String plainText = Html.fromHtml(htmlText).toString();
// LogUtil.v(TAG,"setStatus:plainText:" + plainText);
final SpannableString spannable = new SpannableString(plainText);
Linkify.addLinks(spannable,Linkify.WEB_URLS);
linkifyUsers(spannable,mentions);
linkifyTags(spannable);
removeUnderLines(spannable);
// LogUtil.v(TAG,"setStatus:finalText:" + spannable);
textView.setText(spannable,BufferType.SPANNABLE);
textView.setMovementMethod(LinkMovementMethod.getInstance());
}
项目:droidfan
文件:StatusUtils.java
public static void setItemStatus(final TextView textView,final String text) {
final String htmlText = text + " ";
final List<String> highlightWords = findHighlightWords(htmlText);
final String plainText = Html.fromHtml(htmlText).toString();
final SpannableString spannable = new SpannableString(plainText);
Linkify.addLinks(spannable,Linkify.WEB_URLS);
final Matcher m = PATTERN_USER.matcher(spannable);
while (m.find()) {
int start = m.start(1);
int end = m.end(1);
if (start >= 0 && start < end) {
spannable.setSpan(new ForegroundColorSpan(AppContext.getContext().getResources().getColor(R.color.colorPrimary)),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
linkifyTags(spannable);
removeUnderLines(spannable);
applyHighlightSpan(spannable,highlightWords);
textView.setText(spannable,BufferType.SPANNABLE);
}
项目:Paper-Tales
文件:WallActivity.java
@Override
public CharSequence getTransformation(CharSequence src,View view) {
if (view instanceof TextView) {
TextView textView = (TextView) view;
Linkify.addLinks(textView,Linkify.WEB_URLS);
if (textView.getText() != null && textView.getText() instanceof Spannable) {
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),end = text.getSpanEnd(oldSpan);
String url = oldSpan.getURL();
text.removeSpan(oldSpan);
text.setSpan(new CustomTabsURLSpan(url),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return text;
}
}
return src;
}
项目:Mach3Pendant
文件:Mach3PendantActivity.java
private void showTitlesDialog() {
String aboutTitle = String.format("About %s",getString(R.string.app_name));
String versionString = String.format("Version: %s",getString(R.string.version));
String aboutText = getString(R.string.about);
final TextView message = new TextView(this);
final SpannableString s = new SpannableString(aboutText);
message.setPadding(5,5);
message.setText(versionString + "\n\n" + s);
Linkify.addLinks(message,Linkify.ALL);
new AlertDialog.Builder(this).
setTitle(aboutTitle).
setCancelable(true).
setIcon(R.drawable.icon).
setPositiveButton(this.getString(android.R.string.ok),null).
setView(message).create().show();
}
项目:BLE
文件:MainActivity.java
/**
* 显示项目信息
*/
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,Linkify.ALL);
new AlertDialog.Builder(this).setTitle(R.string.menu_about).setCancelable(false).setPositiveButton(android.R
.string.ok,null)
.setView(textView).show();
}
项目:talk-android
文件:messageformatter.java
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())),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return s;
}
public void testLnkifyPattern1_TransformFilter2() {
String text = inputText1 + inputText2;
Pattern pattern = Pattern.compile("CA");
Linkify.TransformFilter transformFilter = new Linkify.TransformFilter() {
@Override
public String transformUrl(Matcher match,String url) {
return url + "/" + url;
}
};
C1 config = createConfigurator(text);
T2 result = config
.linkify(pattern,"http://www.google.ie/search?q=",transformFilter)
.apply();
assertEquals(text,getText(result));
Object[] spans = getSpans(result);
assertEquals(2,spans.length);
Spanned spanned = toSpanned(result);
assertURLSpan(spanned,spans[0],162,164,33,"http://www.google.ie/search?q=CA/CA");
assertURLSpan(spanned,spans[1],351,353,"http://www.google.ie/search?q=CA/CA");
}
项目:TaskApp
文件:CommentsController.java
/** Helper method to set the contents and visibility of each field */
private void bindView(View view,NoteOrUpdate item) {
// name
final TextView nameView = (TextView)view.findViewById(R.id.title); {
nameView.setText(item.title);
Linkify.addLinks(nameView,Linkify.ALL);
}
// date
final TextView date = (TextView)view.findViewById(R.id.date); {
CharSequence dateString = DateUtils.getRelativeTimeSpanString(item.createdAt,DateUtilities.Now(),DateUtils.MINUTE_IN_MILLIS,DateUtils.FORMAT_ABBREV_RELATIVE);
date.setText(dateString);
}
// picture
final ImageView commentPictureView = (ImageView)view.findViewById(R.id.comment_picture);
setupImagePopupForCommentView(view,commentPictureView,item.commentBitmap,activity);
}
项目:Diccionario
文件:MainActivity.java
@Override
public void showAboutDialog() {
final SpannableString spannableString = new SpannableString(getString(R.string.about_msg));
Linkify.addLinks(spannableString,Linkify.ALL);
final AlertDialog aboutDialog = new AlertDialog.Builder(this)
.setPositiveButton(android.R.string.ok,null)
.setTitle(getString(R.string.app_name) + " " + getString(R.string.app_version))
.setMessage(spannableString)
.create();
aboutDialog.show();
((TextView) aboutDialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}
项目:Audinaut
文件:DetailsAdapter.java
@Override
public View getView(int position,View convertView,ViewGroup parent){
View view;
if(convertView == null) {
view = LayoutInflater.from(getContext()).inflate(R.layout.details_item,null);
} else {
view = convertView;
}
TextView nameView = (TextView) view.findViewById(R.id.detail_name);
TextView detailsView = (TextView) view.findViewById(R.id.detail_value);
nameView.setText(headers.get(position));
detailsView.setText(details.get(position));
Linkify.addLinks(detailsView,Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES);
return view;
}
项目:AndroidChromium
文件:PhysicalWebDiagnosticsPage.java
@Override
protected void initialize(final Activity activity,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()));
}
public void testLinkifyPattern_MatchFilter1() {
String text = inputText1 + inputText2;
Pattern pattern = Pattern.compile("CA");
Linkify.MatchFilter matchFilter = new Linkify.MatchFilter() {
@Override
public boolean acceptMatch(CharSequence cs,int end) {
return start > 162;
}
};
C1 config = createConfigurator(text);
T2 result = config
.linkify(pattern,null)
.apply();
assertEquals(text,getText(result));
Object[] spans = getSpans(result);
assertEquals(1,"http://www.google.ie/search?q=CA");
}
public void testLnkifyPattern1_TransformFilter1() {
String text = inputText1;
Pattern pattern = Pattern.compile("CA");
Linkify.TransformFilter transformFilter = new Linkify.TransformFilter() {
@Override
public String transformUrl(Matcher match,"http://www.google.ie/search?q=CA/CA");
}
项目:easyweather
文件:AboutFragment.java
@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);
}
},textStr.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return view;
}
项目:Better-Link-Movement-Method
文件:MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Add links to all TextViews.
BetterLinkMovementMethod.linkify(Linkify.ALL,this)
.setonLinkClickListener(urlClickListener)
.setonLinkLongClickListener(longClickListener);
TextView waynetowerIntroView = findViewById(R.id.wayne_tower_intro);
waynetowerIntroView.setText(Html.fromHtml(getString(R.string.bettermovementmethod_dummy_text_long)));
BetterLinkMovementMethod.linkifyHtml(waynetowerIntroView)
.setonLinkClickListener(urlClickListener)
.setonLinkLongClickListener(longClickListener);
}
项目:OldDriver-master
文件:HtmlUtils.java
private static SpannableStringBuilder linkifyPlainLinks(CharSequence input,ColorStateList linkTextColor,@ColorInt int linkHighlightColor) {
final SpannableString plainLinks = new SpannableString(input); // copy of input
Linkify.addLinks(plainLinks,Linkify.WEB_URLS);
final URLSpan[] urlSpans = plainLinks.getSpans(0,plainLinks.length(),URLSpan.class);
// add any plain links to the output
final SpannableStringBuilder ssb = new SpannableStringBuilder(input);
for (URLSpan urlSpan : urlSpans) {
ssb.setSpan(new TouchableurlSpan(urlSpan.getURL(),linkTextColor,linkHighlightColor),plainLinks.getSpanStart(urlSpan),plainLinks.getSpanEnd(urlSpan),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return ssb;
}
项目:simpleirc
文件:Messagelistadapter.java
/**
* Get item view for the given position
*
* @param position
* @param convertView
* @param parent
* @return
*/
@Override
public View getView(int position,ViewGroup parent) {
TextView view = (TextView)convertView;
if( view == null ) {
view = new TextView(parent.getContext());
view.setAutoLinkMask(Linkify.ALL);
view.setLinksClickable(true);
view.setTypeface(Typeface.MONOSPACE);
}
view = getItem(position).render(view);
view.setTextSize(_settings.getFontSize());
return view;
}
项目:BeMusic
文件:MainActivity.java
@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);
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;
}
private static void createAndShowDialog(Context context,String title,SpannableString message,boolean showOkButton) {
Linkify.addLinks(message,Patterns.WEB_URL,new Linkify.MatchFilter() {
@Override
public boolean acceptMatch(CharSequence seq,int end) {
return Linkify.sUrlMatchFilter.acceptMatch(seq,end);
}
},null);
final Dialog dialog = new lovelyInfoDialog(context)
.setTopColorRes(R.color.colorPrimaryLight)
.setTitle(title)
.setIcon(R.drawable.ic_info_outline)
.setMessage(message)
.show();
TextView tvMessage = (TextView) dialog.findViewById(R.id.ld_message);
if (tvMessage != null) {
tvMessage.setMovementMethod(LinkMovementMethod.getInstance());
tvMessage.setLinkTextColor(ContextCompat.getColor(context,R.color.blue));
}
if (showOkButton) {
Button btnOk = (Button) dialog.findViewById(R.id.ld_btn_confirm);
if (btnOk != null) {
btnOk.setText(R.string.button_ok);
btnOk.setTextColor(ContextCompat.getColor(context,R.color.colorPrimaryDark));
}
}
}
项目:Forge
文件:GeneratorFragment.java
@Override
public void loadEmail(EmailMessage email) {
if (emailShown) {
// If there is an email dialog shown
// Update the dialog's body text
TextView body = emailDialog.findViewById(R.id.body);
// Hide the progress bar,show the body text
emailDialog.findViewById(R.id.body_loading).setVisibility(View.GONE);
body.setVisibility(View.VISIBLE);
// Make the links clickable
body.setText(linkifyHtml(email.getBody(),Linkify.WEB_URLS));
body.setMovementMethod(LinkMovementMethod.getInstance());
}
}
void bindData(Context context,Comment details) {
CustomTextView.stripUnderlines(context,tvContent,details.getContent(),Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES);
tvContent.setonLongClickListener(new copyTextLongClickListener(context,details.getContent()));
tvDate.setText(Utils.getAllTime(details.getCreatedAt()));
tvName.setText(details.getAuthorName());
if (details.getAttachmentList() != null && details.getAttachmentList().size() > 0) {
ImageAdapter adapter = new ImageAdapter(context,details.getAttachmentList());
mGridView.setVisibility(View.VISIBLE);
mGridView.setAdapter(adapter);
mGridView.setonItemClickListener(new AttachmentItemClickListener(details.getAttachmentList(),context));
mGridView.setonItemLongClickListener(new AttachmentItemLongClickListener(details.getAttachmentList(),context));
} else {
mGridView.setVisibility(View.GONE);
}
switch (details.getMessageStatus()) {
case SUCCESS:
mProgressBar.setVisibility(View.INVISIBLE);
FailedImageView.setVisibility(View.INVISIBLE);
break;
case SENDING:
mProgressBar.setVisibility(View.VISIBLE);
FailedImageView.setVisibility(View.INVISIBLE);
break;
case Failed:
mProgressBar.setVisibility(View.INVISIBLE);
FailedImageView.setVisibility(View.VISIBLE);
break;
default:
break;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。