本文整理汇总了Java中android.text.style.ClickableSpan类的典型用法代码示例。如果您正苦于以下问题:Java ClickableSpan类的具体用法?Java ClickableSpan怎么用?Java ClickableSpan使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClickableSpan类属于android.text.style包,在下文中一共展示了ClickableSpan类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onViewCreated
import android.text.style.ClickableSpan; //导入依赖的package包/类
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
SpannableString ss = new SpannableString(getString(R.string.pick_csv_or_demo_file));
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
if (PermissionHelper.checkOrRequest(CsvPickerFragment.this, REQUEST_CODE_PERMISSION_READ_EXTERNAL_STORAGE_DEMO,
Manifest.permission.READ_EXTERNAL_STORAGE)) {
createDemoFile();
}
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
};
ss.setSpan(clickableSpan, 32, 36, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
tvPickFile.setText(ss);
tvPickFile.setMovementMethod(LinkMovementMethod.getInstance());
tvPickFile.setHighlightColor(Color.TRANSPARENT);
}
示例2: setHtmlWithLinkClickHandler
import android.text.style.ClickableSpan; //导入依赖的package包/类
public static void setHtmlWithLinkClickHandler(TextView tv, String html,
Action1<String> linkClickHandler) {
CharSequence sequence = Html.fromHtml(html);
SpannableStringBuilder strBuilder = new SpannableStringBuilder(sequence);
URLSpan[] urls = strBuilder.getSpans(0, sequence.length(), URLSpan.class);
for (URLSpan span : urls) {
int start = strBuilder.getSpanStart(span);
int end = strBuilder.getSpanEnd(span);
int flags = strBuilder.getSpanFlags(span);
ClickableSpan clickable = new ClickableSpan() {
public void onClick(View view) {
linkClickHandler.call(span.getURL());
}
};
strBuilder.setSpan(clickable, start, end, flags);
strBuilder.removeSpan(span);
}
tv.setText(strBuilder);
tv.setMovementMethod(LinkMovementMethod.getInstance());
}
示例3: changeToLight
import android.text.style.ClickableSpan; //导入依赖的package包/类
/**
* 解析URL和电话号码并高亮显示
*/
private SpannableString changeToLight(String str) {
SpannableString string = new SpannableString(str);
for (Pattern p : mPatterns) {
Matcher m = p.matcher(string);
while (m.find()) {
int start = m.start();
int end = m.end();
string.setSpan(new ClickableSpan() {
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setColor(getColors(R.color.color_theme));
}
@Override
public void onClick(View widget) {
}
}, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return string;
}
示例4: genTimeAndReplyText
import android.text.style.ClickableSpan; //导入依赖的package包/类
private Spannable genTimeAndReplyText(final Comment comment) {
String time = AppTextUtils.getDateFromUnixTime(comment.getDate());
if (comment.getReplyToUser() == 0) {
return Spannable.Factory.getInstance().newSpannable(time);
}
String commentText = context.getString(R.string.comment).toLowerCase();
String target = context.getString(R.string.in_response_to, time, commentText);
int start = target.indexOf(commentText);
Spannable spannable = Spannable.Factory.getInstance().newSpannable(target);
ClickableSpan span = new ClickableSpan() {
@Override
public void onClick(View widget) {
onReplyClick(comment.getReplyToUser(), comment.getReplyToComment());
}
};
spannable.setSpan(span, start, target.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannable;
}
示例5: makeLinksClickable
import android.text.style.ClickableSpan; //导入依赖的package包/类
public static void makeLinksClickable(TextView v) {
SpannableStringBuilder ssb = new SpannableStringBuilder(v.getText());
URLSpan[] spans = ssb.getSpans(0, ssb.length(), URLSpan.class);
for (URLSpan span : spans) {
int start = ssb.getSpanStart(span);
int end = ssb.getSpanEnd(span);
final String url = span.getURL();
ssb.removeSpan(span);
ClickableSpan cSpan = new ClickableSpan() {
@Override
public void onClick(View v2) {
LinkDialogFragment f = LinkDialogFragment.newInstance(url);
FragmentManager fm = ((AppCompatActivity) v2.getContext())
.getSupportFragmentManager();
f.show(fm, f.getUniqueTag());
}
};
ssb.setSpan(cSpan, start, end, 0);
}
v.setText(ssb);
v.setMovementMethod(ArticleMovementMethod.getInstance());
}
示例6: getClickableSpan
import android.text.style.ClickableSpan; //导入依赖的package包/类
/**
* 获取超链接字段
* @return 超链接字符串
*/
private SpannableString getClickableSpan(String aStr) {
int startIndex = aStr.indexOf(mAuthorName);
int endIndex = startIndex + mAuthorName.length();
SpannableString spannableString = new SpannableString(aStr);
//设置下划线文字
// spannableString.setSpan(new UnderlineSpan(), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//设置文字的单击事件
spannableString.setSpan(new ClickableSpan() {
@Override
public void onClick(View widget) {
Uri uri = Uri.parse(mExtLink);
Context context = widget.getContext();
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
context.startActivity(intent);
}
}, startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//设置文字的前景色
spannableString.setSpan(new ForegroundColorSpan(ThemeStyle.Accent), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannableString;
}
示例7: prepareMainMessageString
import android.text.style.ClickableSpan; //导入依赖的package包/类
private CharSequence prepareMainMessageString(final PermissionDialogDelegate delegate) {
SpannableStringBuilder fullString = new SpannableStringBuilder();
String messageText = delegate.getMessageText();
String linkText = delegate.getLinkText();
if (!TextUtils.isEmpty(messageText)) fullString.append(messageText);
// If the linkText exists, then wrap it in a clickable span and concatenate it with the main
// dialog message.
if (!TextUtils.isEmpty(linkText)) {
if (fullString.length() > 0) fullString.append(" ");
int spanStart = fullString.length();
fullString.append(linkText);
fullString.setSpan(new ClickableSpan() {
@Override
public void onClick(View view) {
mDecision = NOT_DECIDED;
delegate.onLinkClicked();
if (mDialog != null) mDialog.dismiss();
}
}, spanStart, fullString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return fullString;
}
示例8: getDescriptionText
import android.text.style.ClickableSpan; //导入依赖的package包/类
private SpannableString getDescriptionText() {
return SpanApplier.applySpans(
getString(R.string.physical_web_optin_description),
new SpanInfo("<learnmore>", "</learnmore>", new ClickableSpan() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(PHYSICAL_WEB_LEARN_MORE_URL));
// Add the SESSION extra to indicate we want a Chrome custom tab. This
// allows the help page to open in the same task as the opt-in activity so
// they can share a back stack.
String session = null;
intent.putExtra(EXTRA_CUSTOM_TABS_SESSION, session);
PhysicalWebOptInActivity.this.startActivity(intent);
}
@Override
public void updateDrawState(TextPaint ds) {
// Color links but do not underline them.
ds.setColor(ds.linkColor);
}
}));
}
示例9: getResetText
import android.text.style.ClickableSpan; //导入依赖的package包/类
private SpannableString getResetText() {
final Context context = getActivity();
return SpanApplier.applySpans(
context.getString(R.string.sync_passphrase_encryption_reset_instructions),
new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
@Override
public void onClick(View view) {
Uri syncDashboardUrl = Uri.parse(
context.getText(R.string.sync_dashboard_url).toString());
Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
intent.setPackage(BuildInfo.getPackageName(context));
IntentUtils.safePutBinderExtra(
intent, CustomTabsIntent.EXTRA_SESSION, null);
context.startActivity(intent);
}
}));
}
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:18,代码来源:PassphraseTypeDialogFragment.java
示例10: getResetText
import android.text.style.ClickableSpan; //导入依赖的package包/类
private SpannableString getResetText() {
final Context context = getActivity();
return SpanApplier.applySpans(
context.getString(R.string.sync_passphrase_reset_instructions),
new SpanInfo("<resetlink>", "</resetlink>", new ClickableSpan() {
@Override
public void onClick(View view) {
recordPassphraseDialogDismissal(PASSPHRASE_DIALOG_RESET_LINK);
Uri syncDashboardUrl = Uri.parse(
context.getText(R.string.sync_dashboard_url).toString());
Intent intent = new Intent(Intent.ACTION_VIEW, syncDashboardUrl);
intent.setPackage(BuildInfo.getPackageName(context));
IntentUtils.safePutBinderExtra(
intent, CustomTabsIntent.EXTRA_SESSION, null);
context.startActivity(intent);
}
}));
}
示例11: createContent
import android.text.style.ClickableSpan; //导入依赖的package包/类
@Override
public void createContent(InfoBarLayout layout) {
super.createContent(layout);
if (mTitleLinkRangeStart != 0 && mTitleLinkRangeEnd != 0) {
SpannableString title = new SpannableString(mTitle);
title.setSpan(new ClickableSpan() {
@Override
public void onClick(View view) {
onLinkClicked();
}
}, mTitleLinkRangeStart, mTitleLinkRangeEnd, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
layout.setMessage(title);
}
InfoBarControlLayout controlLayout = layout.addControlLayout();
if (mUsernames.length > 1) {
InfoBarArrayAdapter<String> usernamesAdapter =
new InfoBarArrayAdapter<String>(getContext(), mUsernames);
mUsernamesSpinner = controlLayout.addSpinner(
R.id.password_infobar_accounts_spinner, usernamesAdapter);
} else {
controlLayout.addDescription(mUsernames[0]);
}
}
示例12: getOfflinePageMessageText
import android.text.style.ClickableSpan; //导入依赖的package包/类
/**
* Gets the infobar text for offline page downloads.
* @param context Context to be used.
* @param template Template of the text to be displayed.
*/
private CharSequence getOfflinePageMessageText(final Context context, final String template) {
return getMessageText(template, mFilePath, new ClickableSpan() {
@Override
public void onClick(View view) {
// TODO(qinmin): open the offline page on local storage instead of opening the url.
// However, there could be multiple stored offline pages for the same url, need to
// figure out which one to use.
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(mPageUrl));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setPackage(context.getPackageName());
context.startActivity(intent);
}
});
}
示例13: prepareMainMessageString
import android.text.style.ClickableSpan; //导入依赖的package包/类
/**
* Prepares text to be displayed as the infobar's main message, including setting up a
* clickable link if the infobar requires it.
*/
private CharSequence prepareMainMessageString() {
SpannableStringBuilder fullString = new SpannableStringBuilder();
if (mMessageMainText != null) fullString.append(mMessageMainText);
// Concatenate the text to display for the link and make it clickable.
if (!TextUtils.isEmpty(mMessageLinkText)) {
if (fullString.length() > 0) fullString.append(" ");
int spanStart = fullString.length();
fullString.append(mMessageLinkText);
fullString.setSpan(new ClickableSpan() {
@Override
public void onClick(View view) {
mInfoBarView.onLinkClicked();
}
}, spanStart, fullString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return fullString;
}
示例14: createContent
import android.text.style.ClickableSpan; //导入依赖的package包/类
@Override
public void createContent(InfoBarLayout layout) {
super.createContent(layout);
InfoBarControlLayout control = layout.addControlLayout();
for (int i = 0; i < mCardDetails.size(); i++) {
CardDetail detail = mCardDetails.get(i);
control.addIcon(detail.issuerIconDrawableId, 0, detail.label, detail.subLabel);
}
for (LegalMessageLine line : mLegalMessageLines) {
SpannableString text = new SpannableString(line.text);
for (final LegalMessageLine.Link link : line.links) {
text.setSpan(new ClickableSpan() {
@Override
public void onClick(View view) {
nativeOnLegalMessageLinkClicked(mNativeAutofillSaveCardInfoBar, link.url);
}
}, link.start, link.end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
control.addDescription(text);
}
}
示例15: createContent
import android.text.style.ClickableSpan; //导入依赖的package包/类
@Override
public void createContent(InfoBarLayout layout) {
super.createContent(layout);
SpannableString message = new SpannableString(mMessageText);
message.setSpan(
new ClickableSpan() {
@Override
public void onClick(View view) {
onLinkClicked();
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
}, mInlineLinkRangeStart, mInlineLinkRangeEnd, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
layout.setMessage(message);
}
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:20,代码来源:SearchGeolocationDisclosureInfoBar.java