use of android.text.style.ClickableSpan in project AntennaPod by AntennaPod.
the class ChaptersListAdapter method getView.
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
Holder holder;
Chapter sc = getItem(position);
// Inflate Layout
if (convertView == null) {
holder = new Holder();
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.simplechapter_item, parent, false);
holder.view = convertView;
holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
defaultTextColor = holder.title.getTextColors().getDefaultColor();
holder.start = (TextView) convertView.findViewById(R.id.txtvStart);
holder.link = (TextView) convertView.findViewById(R.id.txtvLink);
holder.butPlayChapter = (ImageButton) convertView.findViewById(R.id.butPlayChapter);
convertView.setTag(holder);
} else {
holder = (Holder) convertView.getTag();
}
holder.title.setText(sc.getTitle());
holder.start.setText(Converter.getDurationStringLong((int) sc.getStart()));
if (sc.getLink() != null) {
holder.link.setVisibility(View.VISIBLE);
holder.link.setText(sc.getLink());
Linkify.addLinks(holder.link, Linkify.WEB_URLS);
} else {
holder.link.setVisibility(View.GONE);
}
holder.link.setMovementMethod(null);
holder.link.setOnTouchListener((v, event) -> {
// from
// http://stackoverflow.com/questions/7236840/android-textview-linkify-intercepts-with-parent-view-gestures
TextView widget = (TextView) v;
Object text = widget.getText();
if (text instanceof Spanned) {
Spannable buffer = (Spannable) text;
int action = event.getAction();
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();
x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();
x += widget.getScrollX();
y += widget.getScrollY();
Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
if (link.length != 0) {
if (action == MotionEvent.ACTION_UP) {
link[0].onClick(widget);
} else if (action == MotionEvent.ACTION_DOWN) {
Selection.setSelection(buffer, buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0]));
}
return true;
}
}
}
return false;
});
holder.butPlayChapter.setOnClickListener(v -> {
if (callback != null) {
callback.onPlayChapterButtonClicked(position);
}
});
Chapter current = ChapterUtils.getCurrentChapter(media);
if (current != null) {
if (current == sc) {
int playingBackGroundColor;
if (UserPreferences.getTheme() == R.style.Theme_AntennaPod_Dark) {
playingBackGroundColor = ContextCompat.getColor(getContext(), R.color.highlight_dark);
} else {
playingBackGroundColor = ContextCompat.getColor(getContext(), R.color.highlight_light);
}
holder.view.setBackgroundColor(playingBackGroundColor);
} else {
holder.view.setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
holder.title.setTextColor(defaultTextColor);
holder.start.setTextColor(defaultTextColor);
}
} else {
Log.w(TAG, "Could not find out what the current chapter is.");
}
return convertView;
}
use of android.text.style.ClickableSpan in project AndroidChromium by JackyAndroid.
the class AutoSigninFirstRunDialog method show.
private void show() {
final AlertDialog.Builder builder = new AlertDialog.Builder(mContext, R.style.AlertDialogTheme).setTitle(mTitle).setPositiveButton(mOkButtonText, this).setNegativeButton(mTurnOffButtonText, this);
View view = LayoutInflater.from(mContext).inflate(R.layout.auto_sign_in_first_run_dialog, null);
TextView summaryView = (TextView) view.findViewById(R.id.summary);
if (mExplanationLinkStart != mExplanationLinkEnd && mExplanationLinkEnd != 0) {
SpannableString spanableExplanation = new SpannableString(mExplanation);
spanableExplanation.setSpan(new ClickableSpan() {
@Override
public void onClick(View view) {
nativeOnLinkClicked(mNativeAutoSigninFirstRunDialog);
mDialog.dismiss();
}
}, mExplanationLinkStart, mExplanationLinkEnd, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
summaryView.setText(spanableExplanation);
summaryView.setMovementMethod(LinkMovementMethod.getInstance());
} else {
summaryView.setText(mExplanation);
summaryView.setMovementMethod(LinkMovementMethod.getInstance());
}
builder.setView(view);
mDialog = builder.create();
mDialog.setCanceledOnTouchOutside(false);
mDialog.setOnDismissListener(this);
mDialog.show();
}
use of android.text.style.ClickableSpan in project AndroidChromium by JackyAndroid.
the class PhysicalWebOptInActivity method getDescriptionText.
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);
}
}));
}
use of android.text.style.ClickableSpan in project AndroidChromium by JackyAndroid.
the class TranslateInfoBar method formatBeforeInfoBarMessage.
/**
* @return a formatted message with links to {@code panelId}.
*/
private CharSequence formatBeforeInfoBarMessage(String template, String sourceLanguage, String targetLanguage, final int panelId) {
SpannableString formattedSourceLanguage = new SpannableString(sourceLanguage);
formattedSourceLanguage.setSpan(new ClickableSpan() {
@Override
public void onClick(View view) {
swapPanel(panelId);
}
}, 0, sourceLanguage.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
SpannableString formattedTargetLanguage = new SpannableString(targetLanguage);
formattedTargetLanguage.setSpan(new ClickableSpan() {
@Override
public void onClick(View view) {
swapPanel(panelId);
}
}, 0, targetLanguage.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return TextUtils.expandTemplate(template, formattedSourceLanguage, formattedTargetLanguage);
}
use of android.text.style.ClickableSpan in project AndroidChromium by JackyAndroid.
the class TranslateInfoBar method formatAfterTranslateInfoBarMessage.
/**
* @return a formatted message with a link to {@code panelId}
*/
private CharSequence formatAfterTranslateInfoBarMessage(String statement, String linkText, final int panelId) {
SpannableStringBuilder result = new SpannableStringBuilder();
result.append(statement).append(" ");
SpannableString formattedChange = new SpannableString(linkText);
formattedChange.setSpan(new ClickableSpan() {
@Override
public void onClick(View view) {
swapPanel(panelId);
}
}, 0, linkText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
result.append(formattedChange);
return result;
}
Aggregations