List of usage examples for android.text.method LinkMovementMethod getInstance
public static MovementMethod getInstance()
From source file:com.google.samples.apps.iosched.myschedule.MyScheduleActivity.java
private void showAnnouncementDialogIfNeeded(Intent intent) { final String title = intent.getStringExtra(EXTRA_DIALOG_TITLE); final String message = intent.getStringExtra(EXTRA_DIALOG_MESSAGE); if (!mShowedAnnouncementDialog && !TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) { LOGD(TAG, "showAnnouncementDialogIfNeeded, title: " + title); LOGD(TAG, "showAnnouncementDialogIfNeeded, message: " + message); final String yes = intent.getStringExtra(EXTRA_DIALOG_YES); LOGD(TAG, "showAnnouncementDialogIfNeeded, yes: " + yes); final String no = intent.getStringExtra(EXTRA_DIALOG_NO); LOGD(TAG, "showAnnouncementDialogIfNeeded, no: " + no); final String url = intent.getStringExtra(EXTRA_DIALOG_URL); LOGD(TAG, "showAnnouncementDialogIfNeeded, url: " + url); final SpannableString spannable = new SpannableString(message == null ? "" : message); Linkify.addLinks(spannable, Linkify.WEB_URLS); AlertDialog.Builder builder = new AlertDialog.Builder(this); if (!TextUtils.isEmpty(title)) { builder.setTitle(title);//from w ww.j a v a 2 s. c om } builder.setMessage(spannable); if (!TextUtils.isEmpty(no)) { builder.setNegativeButton(no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); } if (!TextUtils.isEmpty(yes)) { builder.setPositiveButton(yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(intent); } }); } final AlertDialog dialog = builder.create(); dialog.show(); final TextView messageView = (TextView) dialog.findViewById(android.R.id.message); if (messageView != null) { // makes the embedded links in the text clickable, if there are any messageView.setMovementMethod(LinkMovementMethod.getInstance()); } mShowedAnnouncementDialog = true; } }
From source file:org.schabi.newpipe.VideoItemDetailFragment.java
private void updateInfo(final StreamInfo info) { try {/* w w w . ja v a 2s . c om*/ Context c = getContext(); VideoInfoItemViewCreator videoItemViewCreator = new VideoInfoItemViewCreator( LayoutInflater.from(getActivity())); RelativeLayout textContentLayout = (RelativeLayout) activity.findViewById(R.id.detailTextContentLayout); final TextView videoTitleView = (TextView) activity.findViewById(R.id.detailVideoTitleView); TextView uploaderView = (TextView) activity.findViewById(R.id.detailUploaderView); TextView viewCountView = (TextView) activity.findViewById(R.id.detailViewCountView); TextView thumbsUpView = (TextView) activity.findViewById(R.id.detailThumbsUpCountView); TextView thumbsDownView = (TextView) activity.findViewById(R.id.detailThumbsDownCountView); TextView uploadDateView = (TextView) activity.findViewById(R.id.detailUploadDateView); TextView descriptionView = (TextView) activity.findViewById(R.id.detailDescriptionView); FrameLayout nextVideoFrame = (FrameLayout) activity.findViewById(R.id.detailNextVideoFrame); RelativeLayout nextVideoRootFrame = (RelativeLayout) activity .findViewById(R.id.detailNextVideoRootLayout); Button nextVideoButton = (Button) activity.findViewById(R.id.detailNextVideoButton); TextView similarTitle = (TextView) activity.findViewById(R.id.detailSimilarTitle); Button backgroundButton = (Button) activity .findViewById(R.id.detailVideoThumbnailWindowBackgroundButton); View topView = activity.findViewById(R.id.detailTopView); View nextVideoView = null; if (info.next_video != null) { nextVideoView = videoItemViewCreator.getViewFromVideoInfoItem(null, nextVideoFrame, info.next_video); } else { activity.findViewById(R.id.detailNextVidButtonAndContentLayout).setVisibility(View.GONE); activity.findViewById(R.id.detailNextVideoTitle).setVisibility(View.GONE); activity.findViewById(R.id.detailNextVideoButton).setVisibility(View.GONE); } progressBar.setVisibility(View.GONE); if (nextVideoView != null) { nextVideoFrame.addView(nextVideoView); } initThumbnailViews(info, nextVideoFrame); textContentLayout.setVisibility(View.VISIBLE); if (android.os.Build.VERSION.SDK_INT < 18) { playVideoButton.setVisibility(View.VISIBLE); } else { ImageView playArrowView = (ImageView) activity.findViewById(R.id.playArrowView); playArrowView.setVisibility(View.VISIBLE); } if (!showNextVideoItem) { nextVideoRootFrame.setVisibility(View.GONE); similarTitle.setVisibility(View.GONE); } videoTitleView.setText(info.title); topView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == android.view.MotionEvent.ACTION_UP) { ImageView arrow = (ImageView) activity.findViewById(R.id.toggleDescriptionView); View extra = activity.findViewById(R.id.detailExtraView); if (extra.getVisibility() == View.VISIBLE) { extra.setVisibility(View.GONE); arrow.setImageResource(R.drawable.arrow_down); } else { extra.setVisibility(View.VISIBLE); arrow.setImageResource(R.drawable.arrow_up); } } return true; } }); // Since newpipe is designed to work even if certain information is not available, // the UI has to react on missing information. videoTitleView.setText(info.title); if (!info.uploader.isEmpty()) { uploaderView.setText(info.uploader); } else { activity.findViewById(R.id.detailUploaderWrapView).setVisibility(View.GONE); } if (info.view_count >= 0) { viewCountView.setText(Localization.localizeViewCount(info.view_count, c)); } else { viewCountView.setVisibility(View.GONE); } if (info.dislike_count >= 0) { thumbsDownView.setText(Localization.localizeNumber(info.dislike_count, c)); } else { thumbsDownView.setVisibility(View.INVISIBLE); activity.findViewById(R.id.detailThumbsDownImgView).setVisibility(View.GONE); } if (info.like_count >= 0) { thumbsUpView.setText(Localization.localizeNumber(info.like_count, c)); } else { thumbsUpView.setVisibility(View.GONE); activity.findViewById(R.id.detailThumbsUpImgView).setVisibility(View.GONE); thumbsDownView.setVisibility(View.GONE); activity.findViewById(R.id.detailThumbsDownImgView).setVisibility(View.GONE); } if (!info.upload_date.isEmpty()) { uploadDateView.setText(Localization.localizeDate(info.upload_date, c)); } else { uploadDateView.setVisibility(View.GONE); } if (!info.description.isEmpty()) { descriptionView.setText(Html.fromHtml(info.description)); } else { descriptionView.setVisibility(View.GONE); } descriptionView.setMovementMethod(LinkMovementMethod.getInstance()); // parse streams Vector<VideoStream> streamsToUse = new Vector<>(); for (VideoStream i : info.video_streams) { if (useStream(i, streamsToUse)) { streamsToUse.add(i); } } nextVideoButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent detailIntent = new Intent(getActivity(), VideoItemDetailActivity.class); /*detailIntent.putExtra( VideoItemDetailFragment.ARG_ITEM_ID, currentVideoInfo.nextVideo.id); */ detailIntent.putExtra(VideoItemDetailFragment.VIDEO_URL, info.next_video.webpage_url); detailIntent.putExtra(VideoItemDetailFragment.STREAMING_SERVICE, streamingServiceId); startActivity(detailIntent); } }); textContentLayout.setVisibility(View.VISIBLE); if (info.related_videos != null && !info.related_videos.isEmpty()) { initSimilarVideos(info, videoItemViewCreator); } else { activity.findViewById(R.id.detailSimilarTitle).setVisibility(View.GONE); activity.findViewById(R.id.similarVideosView).setVisibility(View.GONE); } setupActionBarHandler(info); if (autoPlayEnabled) { playVideo(info); } if (android.os.Build.VERSION.SDK_INT < 18) { playVideoButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { playVideo(info); } }); } backgroundButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { playVideo(info); } }); } catch (java.lang.NullPointerException e) { Log.w(TAG, "updateInfo(): Fragment closed before thread ended work... or else"); e.printStackTrace(); } }
From source file:org.sufficientlysecure.ical.ui.MainActivity.java
private void showLegalNotices() { TextView text = new TextView(this); text.setText(Html.fromHtml(getString(R.string.legal_notices_html))); text.setMovementMethod(LinkMovementMethod.getInstance()); new AlertDialog.Builder(this).setView(text).create().show(); }
From source file:de.vanita5.twittnuker.fragment.support.StatusFragment.java
public void displayStatus(final ParcelableStatus status) { final boolean status_unchanged = mStatus != null && status != null && status.equals(mStatus); if (!status_unchanged) { getListAdapter().setData(null);/*ww w .ja v a2 s . c o m*/ } else { setSelection(0); } if (mConversationTask != null && mConversationTask.getStatus() == AsyncTask.Status.RUNNING) { mConversationTask.cancel(true); } mStatus = status; if (!status_unchanged) { clearPreviewImages(); hidePreviewImages(); } if (status == null || getActivity() == null) return; final Bundle args = getArguments(); args.putLong(EXTRA_ACCOUNT_ID, status.account_id); args.putLong(EXTRA_STATUS_ID, status.id); args.putParcelable(EXTRA_STATUS, status); if (shouldUseNativeMenu()) { getActivity().supportInvalidateOptionsMenu(); } else { setMenuForStatus(getActivity(), mMenuBar.getMenu(), status); mMenuBar.show(); } updateUserColor(); mProfileView.drawEnd(getAccountColor(getActivity(), status.account_id)); final boolean nickname_only = mPreferences.getBoolean(KEY_NICKNAME_ONLY, false); final boolean name_first = mPreferences.getBoolean(KEY_NAME_FIRST, true); final boolean display_image_preview = mPreferences.getBoolean(KEY_DISPLAY_IMAGE_PREVIEW, false); final String nick = getUserNickname(getActivity(), status.user_id, true); mNameView.setText(TextUtils.isEmpty(nick) ? status.user_name : nickname_only ? nick : getString(R.string.name_with_nickname, status.user_name, nick)); mNameView.setCompoundDrawablesWithIntrinsicBounds(0, 0, getUserTypeIconRes(status.user_is_verified, status.user_is_protected), 0); mScreenNameView.setText("@" + status.user_screen_name); mTextView.setText(Html.fromHtml(status.text_html)); final TwidereLinkify linkify = new TwidereLinkify( new OnLinkClickHandler(getActivity(), getMultiSelectManager())); linkify.setLinkTextColor(ThemeUtils.getUserLinkTextColor(getActivity())); linkify.applyAllLinks(mTextView, status.account_id, status.is_possibly_sensitive); mTextView.setMovementMethod(StatusContentMovementMethod.getInstance()); mTextView.setCustomSelectionActionModeCallback(this); final String timeString = formatToLongTimeString(getActivity(), status.timestamp); final String sourceHtml = status.source; if (!isEmpty(timeString) && !isEmpty(sourceHtml)) { mTimeSourceView.setText(Html.fromHtml(getString(R.string.time_source, timeString, sourceHtml))); } else if (isEmpty(timeString) && !isEmpty(sourceHtml)) { mTimeSourceView.setText(Html.fromHtml(getString(R.string.source, sourceHtml))); } else if (!isEmpty(timeString) && isEmpty(sourceHtml)) { mTimeSourceView.setText(timeString); } mTimeSourceView.setMovementMethod(LinkMovementMethod.getInstance()); final String in_reply_to = getDisplayName(getActivity(), status.in_reply_to_user_id, status.in_reply_to_name, status.in_reply_to_screen_name, name_first, nickname_only, true); mInReplyToView.setText(getString(R.string.in_reply_to, in_reply_to)); if (mPreferences.getBoolean(KEY_DISPLAY_PROFILE_IMAGE, true)) { mImageLoader.displayProfileImage(mProfileImageView, status.user_profile_image_url); } else { mProfileImageView.setImageResource(R.drawable.ic_profile_image_default); } mImagePreviewContainer .setVisibility(status.medias == null || status.medias.length == 0 ? View.GONE : View.VISIBLE); if (display_image_preview) { loadPreviewImages(); } mRetweetsContainer.setVisibility(!status.user_is_protected ? View.VISIBLE : View.GONE); mRetweetsCountView.setText(getLocalizedNumber(mLocale, status.retweet_count)); mFavoritesCountView.setText(getLocalizedNumber(mLocale, status.favorite_count)); final ParcelableLocation location = status.location; final boolean is_valid_location = ParcelableLocation.isValidLocation(location); mLocationContainer.setVisibility(is_valid_location ? View.VISIBLE : View.GONE); if (display_image_preview) { mMapView.setVisibility(is_valid_location ? View.VISIBLE : View.GONE); mLocationBackgroundView.setVisibility(is_valid_location ? View.VISIBLE : View.GONE); mLocationView.setVisibility(View.VISIBLE); if (is_valid_location) { mHandler.post(new DisplayMapRunnable(location, mImageLoader, mMapView)); } else { mMapView.setImageDrawable(null); } } else { mMapView.setVisibility(View.GONE); mLocationBackgroundView.setVisibility(View.GONE); mMapView.setImageDrawable(null); mLocationView.setVisibility(View.VISIBLE); } if (mLoadMoreAutomatically) { showFollowInfo(true); showLocationInfo(true); showConversation(); } else if (mLoadConversationsAutomatically) { showConversation(); } else { mFollowIndicator.setVisibility(View.GONE); } updateConversationInfo(); scrollToStart(); }
From source file:com.google.android.apps.iosched.ui.SessionDetailFragment.java
/** * Build and add "notes" tab.//from w ww. jav a 2 s.com */ private void setupNotesTab() { // Make powered-by clickable ((TextView) mRootView.findViewById(R.id.notes_powered_by)) .setMovementMethod(LinkMovementMethod.getInstance()); // Setup tab mTabHost.addTab(mTabHost.newTabSpec(TAG_NOTES).setIndicator(buildIndicator(R.string.session_notes)) .setContent(R.id.tab_session_notes)); }
From source file:com.razza.apps.iosched.myschedule.MyScheduleActivity.java
private void showAnnouncementDialogIfNeeded(Intent intent) { final String title = intent.getStringExtra(EXTRA_DIALOG_TITLE); final String message = intent.getStringExtra(EXTRA_DIALOG_MESSAGE); if (!mShowedAnnouncementDialog && !TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) { LogUtils.LOGD(TAG, "showAnnouncementDialogIfNeeded, title: " + title); LogUtils.LOGD(TAG, "showAnnouncementDialogIfNeeded, message: " + message); final String yes = intent.getStringExtra(EXTRA_DIALOG_YES); LogUtils.LOGD(TAG, "showAnnouncementDialogIfNeeded, yes: " + yes); final String no = intent.getStringExtra(EXTRA_DIALOG_NO); LogUtils.LOGD(TAG, "showAnnouncementDialogIfNeeded, no: " + no); final String url = intent.getStringExtra(EXTRA_DIALOG_URL); LogUtils.LOGD(TAG, "showAnnouncementDialogIfNeeded, url: " + url); final SpannableString spannable = new SpannableString(message == null ? "" : message); Linkify.addLinks(spannable, Linkify.WEB_URLS); AlertDialog.Builder builder = new AlertDialog.Builder(this); if (!TextUtils.isEmpty(title)) { builder.setTitle(title);//from www .j a v a 2 s . c om } builder.setMessage(spannable); if (!TextUtils.isEmpty(no)) { builder.setNegativeButton(no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); } if (!TextUtils.isEmpty(yes)) { builder.setPositiveButton(yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(intent); } }); } final AlertDialog dialog = builder.create(); dialog.show(); final TextView messageView = (TextView) dialog.findViewById(android.R.id.message); if (messageView != null) { // makes the embedded links in the text clickable, if there are any messageView.setMovementMethod(LinkMovementMethod.getInstance()); } mShowedAnnouncementDialog = true; } }
From source file:org.tlhInganHol.android.klingonassistant.EntryActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // TTS://from w w w .j a va 2 s .c o m // Initialize text-to-speech. This is an asynchronous operation. // The OnInitListener (second argument) is called after initialization completes. // Log.d(TAG, "Initialising TTS"); mTts = new TextToSpeech(this, this, // TextToSpeech.OnInitListener "org.tlhInganHol.android.klingonttsengine"); // Requires API 14. setDrawerContentView(R.layout.entry); Resources resources = getResources(); JellyBeanSpanFixTextView entryTitle = (JellyBeanSpanFixTextView) findViewById(R.id.entry_title); JellyBeanSpanFixTextView entryText = (JellyBeanSpanFixTextView) findViewById(R.id.definition); // TODO: Save and restore bundle state to preserve links. Uri uri = getIntent().getData(); // Log.d(TAG, "EntryActivity - uri: " + uri.toString()); // TODO: Disable the "About" menu item if this is the "About" entry. mParentQuery = getIntent().getStringExtra(SearchManager.QUERY); // Retrieve the entry's data. // Note: managedQuery is deprecated since API 11. Cursor cursor = managedQuery(uri, KlingonContentDatabase.ALL_KEYS, null, null, null); KlingonContentProvider.Entry entry = new KlingonContentProvider.Entry(cursor, getBaseContext()); // Handle alternative spellings here. if (entry.isAlternativeSpelling()) { // TODO: Immediate redirect to query in entry.getDefinition(); } // Get the shared preferences. SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); // Set the entry's name (along with info like "slang", formatted in HTML). entryTitle.invalidate(); boolean useKlingonFont = sharedPrefs.getBoolean(Preferences.KEY_KLINGON_FONT_CHECKBOX_PREFERENCE, /* default */false); Typeface klingonTypeface = KlingonAssistant.getKlingonFontTypeface(getBaseContext()); if (useKlingonFont) { // Preference is set to display this in {pIqaD}! entryTitle.setTypeface(klingonTypeface); entryTitle.setText(entry.getEntryNameInKlingonFont()); } else { // Boring transcription based on English (Latin) alphabet. entryTitle.setText(Html.fromHtml(entry.getFormattedEntryName(/* isHtml */true))); } mEntryName = entry.getEntryName(); // Set the colour for the entry name depending on its part of speech. boolean useColours = sharedPrefs.getBoolean(Preferences.KEY_USE_COLOURS_CHECKBOX_PREFERENCE, /* default */true); if (useColours) { entryTitle.setTextColor(entry.getTextColor()); } // Create the expanded definition. String pos = entry.getFormattedPartOfSpeech(/* isHtml */false); String expandedDefinition = pos + entry.getDefinition(); // Show the German definition. String definition_DE = ""; boolean displayGermanEntry = entry.shouldDisplayGerman(); int germanDefinitionStart = -1; String germanDefinitionHeader = "\n" + resources.getString(R.string.label_german) + ": "; if (displayGermanEntry) { germanDefinitionStart = expandedDefinition.length(); definition_DE = entry.getDefinition_DE(); expandedDefinition += germanDefinitionHeader + definition_DE; } // Set the share intent. setShareEntryIntent(entry); // Show the basic notes. String notes = entry.getNotes(); if (!notes.equals("")) { expandedDefinition += "\n\n" + notes; } // If this entry is hypothetical or extended canon, display warnings. if (entry.isHypothetical() || entry.isExtendedCanon()) { expandedDefinition += "\n\n"; if (entry.isHypothetical()) { expandedDefinition += resources.getString(R.string.warning_hypothetical); } if (entry.isExtendedCanon()) { expandedDefinition += resources.getString(R.string.warning_extended_canon); } } // Show synonyms, antonyms, and related entries. String synonyms = entry.getSynonyms(); String antonyms = entry.getAntonyms(); String seeAlso = entry.getSeeAlso(); if (!synonyms.equals("")) { expandedDefinition += "\n\n" + resources.getString(R.string.label_synonyms) + ": " + synonyms; } if (!antonyms.equals("")) { expandedDefinition += "\n\n" + resources.getString(R.string.label_antonyms) + ": " + antonyms; } if (!seeAlso.equals("")) { expandedDefinition += "\n\n" + resources.getString(R.string.label_see_also) + ": " + seeAlso; } // Display components if that field is not empty, unless we are showing an analysis link, in // which case we want to hide the components. boolean showAnalysis = entry.isSentence() || entry.isDerivative(); String components = entry.getComponents(); if (!components.equals("")) { // Treat the components column of inherent plurals and their // singulars differently than for other entries. if (entry.isInherentPlural()) { expandedDefinition += "\n\n" + String.format(resources.getString(R.string.info_inherent_plural), components); } else if (entry.isSingularFormOfInherentPlural()) { expandedDefinition += "\n\n" + String.format(resources.getString(R.string.info_singular_form), components); } else if (!showAnalysis) { // This is just a regular list of components. expandedDefinition += "\n\n" + resources.getString(R.string.label_components) + ": " + components; } } // Display plural information. if (!entry.isPlural() && !entry.isInherentPlural() && !entry.isPlural()) { if (entry.isBeingCapableOfLanguage()) { expandedDefinition += "\n\n" + resources.getString(R.string.info_being); } else if (entry.isBodyPart()) { expandedDefinition += "\n\n" + resources.getString(R.string.info_body); } } // If the entry is a useful phrase, link back to its category. if (entry.isSentence()) { String sentenceType = entry.getSentenceType(); if (!sentenceType.equals("")) { // Put the query as a placeholder for the actual category. expandedDefinition += "\n\n" + resources.getString(R.string.label_category) + ": {" + entry.getSentenceTypeQuery() + "}"; } } // If the entry is a sentence, make a link to analyse its components. if (showAnalysis) { String analysisQuery = entry.getEntryName(); if (!components.equals("")) { // Strip the brackets around each component so they won't be processed. analysisQuery += ":" + entry.getPartOfSpeech(); int homophoneNumber = entry.getHomophoneNumber(); if (homophoneNumber != -1) { analysisQuery += ":" + homophoneNumber; } analysisQuery += KlingonContentProvider.Entry.COMPONENTS_MARKER + components.replaceAll("[{}]", ""); } expandedDefinition += "\n\n" + resources.getString(R.string.label_analyze) + ": {" + analysisQuery + "}"; } // Show the examples. String examples = entry.getExamples(); if (!examples.equals("")) { expandedDefinition += "\n\n" + resources.getString(R.string.label_examples) + ": " + examples; } // Show the source. String source = entry.getSource(); if (!source.equals("")) { expandedDefinition += "\n\n" + resources.getString(R.string.label_sources) + ": " + source; } // If this is a verb (but not a prefix or suffix), show the transitivity information. String transitivity = ""; if (entry.isVerb() && sharedPrefs.getBoolean(Preferences.KEY_SHOW_TRANSITIVITY_CHECKBOX_PREFERENCE, /* default */ true)) { // This is a verb and show transitivity preference is set to true. transitivity = entry.getTransitivityString(); } int transitivityStart = -1; String transitivityHeader = "\n\n" + resources.getString(R.string.label_transitivity) + ": "; boolean showTransitivityInformation = !transitivity.equals(""); if (showTransitivityInformation) { transitivityStart = expandedDefinition.length(); expandedDefinition += transitivityHeader + transitivity; } // Show the hidden notes. String hiddenNotes = ""; if (sharedPrefs.getBoolean(Preferences.KEY_SHOW_ADDITIONAL_INFORMATION_CHECKBOX_PREFERENCE, /* default */ true)) { // Show additional information preference set to true. hiddenNotes = entry.getHiddenNotes(); } int hiddenNotesStart = -1; String hiddenNotesHeader = "\n\n" + resources.getString(R.string.label_additional_information) + ": "; if (!hiddenNotes.equals("")) { hiddenNotesStart = expandedDefinition.length(); expandedDefinition += hiddenNotesHeader + hiddenNotes; } // Format the expanded definition, including linkifying the links to other entries. float smallTextScale = (float) 0.8; SpannableStringBuilder ssb = new SpannableStringBuilder(expandedDefinition); int intermediateFlags = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_INTERMEDIATE; int finalFlags = Spanned.SPAN_EXCLUSIVE_EXCLUSIVE; if (!pos.equals("")) { // Italicise the part of speech. ssb.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, pos.length(), finalFlags); } if (displayGermanEntry) { // Reduce the size of the German definition. ssb.setSpan(new RelativeSizeSpan(smallTextScale), germanDefinitionStart, germanDefinitionStart + germanDefinitionHeader.length() + definition_DE.length(), finalFlags); } if (showTransitivityInformation) { // Reduce the size of the transitivity information. ssb.setSpan(new RelativeSizeSpan(smallTextScale), transitivityStart, transitivityStart + transitivityHeader.length() + transitivity.length(), finalFlags); } if (!hiddenNotes.equals("")) { // Reduce the size of the hidden notes. ssb.setSpan(new RelativeSizeSpan(smallTextScale), hiddenNotesStart, hiddenNotesStart + hiddenNotesHeader.length() + hiddenNotes.length(), finalFlags); } Matcher m = KlingonContentProvider.Entry.ENTRY_PATTERN.matcher(expandedDefinition); while (m.find()) { // Strip the brackets {} to get the query. String query = expandedDefinition.substring(m.start() + 1, m.end() - 1); LookupClickableSpan viewLauncher = new LookupClickableSpan(query); // Process the linked entry information. KlingonContentProvider.Entry linkedEntry = new KlingonContentProvider.Entry(query, getBaseContext()); // Log.d(TAG, "linkedEntry.getEntryName() = " + linkedEntry.getEntryName()); // Delete the brackets and metadata parts of the string (which includes analysis components). ssb.delete(m.start() + 1 + linkedEntry.getEntryName().length(), m.end()); ssb.delete(m.start(), m.start() + 1); int end = m.start() + linkedEntry.getEntryName().length(); // Insert link to the category for a useful phrase. if (entry.isSentence() && !entry.getSentenceType().equals("") && linkedEntry.getEntryName().equals("*")) { // Delete the "*" placeholder. ssb.delete(m.start(), m.start() + 1); // Insert the category name. ssb.insert(m.start(), entry.getSentenceType()); end += entry.getSentenceType().length() - 1; } // Set the font and link. // TODO: Source should link to description of the source. // This is true if this entry doesn't launch an EntryActivity. boolean disableEntryLink = linkedEntry.doNotLink() || linkedEntry.isSource() || linkedEntry.isURL(); // The last span set on a range must have finalFlags. int maybeFinalFlags = disableEntryLink ? finalFlags : intermediateFlags; if (linkedEntry.isSource()) { // Names of sources are in italics. ssb.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), m.start(), end, maybeFinalFlags); } else if (linkedEntry.isURL()) { // Linkify URL if there is one. String url = linkedEntry.getURL(); if (!url.equals("")) { ssb.setSpan(new URLSpan(url), m.start(), end, maybeFinalFlags); } } else if (useKlingonFont) { // Display the text using the Klingon font. Categories (which have an entry of "*") must // be handled specially. String klingonEntryName = !linkedEntry.getEntryName().equals("*") ? linkedEntry.getEntryNameInKlingonFont() : KlingonContentProvider.convertStringToKlingonFont(entry.getSentenceType()); ssb.delete(m.start(), end); ssb.insert(m.start(), klingonEntryName); end = m.start() + klingonEntryName.length(); ssb.setSpan(new KlingonTypefaceSpan("", klingonTypeface), m.start(), end, maybeFinalFlags); } else { // Klingon is in bold serif. ssb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), m.start(), end, intermediateFlags); ssb.setSpan(new TypefaceSpan("serif"), m.start(), end, maybeFinalFlags); } // If linked entry is hypothetical or extended canon, insert a "?" in front. if (linkedEntry.isHypothetical() || linkedEntry.isExtendedCanon()) { ssb.insert(m.start(), "?"); ssb.setSpan(new RelativeSizeSpan(smallTextScale), m.start(), m.start() + 1, intermediateFlags); ssb.setSpan(new SuperscriptSpan(), m.start(), m.start() + 1, maybeFinalFlags); end++; } // Only apply colours to verbs, nouns, and affixes (exclude BLUE and WHITE). if (!disableEntryLink) { // Link to view launcher. ssb.setSpan(viewLauncher, m.start(), end, useColours ? intermediateFlags : finalFlags); } // Set the colour last, so it's not overridden by other spans. if (useColours) { ssb.setSpan(new ForegroundColorSpan(linkedEntry.getTextColor()), m.start(), end, finalFlags); } String linkedPos = linkedEntry.getBracketedPartOfSpeech(/* isHtml */false); if (!linkedPos.equals("") && linkedPos.length() > 1) { ssb.insert(end, linkedPos); int rightBracketLoc = linkedPos.indexOf(")"); if (rightBracketLoc != -1) { // linkedPos is always of the form " (pos)[ (def'n N)]", we want to italicise // the "pos" part only. ssb.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), end + 2, end + rightBracketLoc, finalFlags); } } // Rinse and repeat. expandedDefinition = ssb.toString(); m = KlingonContentProvider.Entry.ENTRY_PATTERN.matcher(expandedDefinition); } // Display the entry name and definition. entryText.invalidate(); entryText.setText(ssb); entryText.setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:com.andfchat.frontend.activities.ChatScreen.java
public void showDescription() { LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.popup_description, null); int height = (int) (this.height * 0.8f); int width = (int) (this.width * 0.8f); final PopupWindow descriptionPopup = new FListPopupWindow(layout, width, height); descriptionPopup.showAtLocation(chatFragment.getView(), Gravity.CENTER, 0, 0); final TextView descriptionText = (TextView) layout.findViewById(R.id.descriptionText); descriptionText.setText(SmileyReader.addSmileys(this, chatroomManager.getActiveChat().getDescription())); // Enable touching/clicking links in text descriptionText.setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:com.near.chimerarevo.fragments.PostFragment.java
private void addText(String text, boolean isHTML, Typeface tf) { TextViewEx txt = new TextViewEx(getActivity()); boolean justifyText = PreferenceManager.getDefaultSharedPreferences(getActivity()) .getBoolean("justify_text_pref", false); if (isHTML) { txt.setText(Html.fromHtml(text), justifyText); txt.setLinksClickable(true);//w w w . j a v a 2s . c om Linkify.addLinks(txt, Linkify.WEB_URLS); txt.setTextIsSelectable(true); txt.setMovementMethod(LinkMovementMethod.getInstance()); } else { txt.setText(text, justifyText); txt.setTextIsSelectable(true); } int textSize = PreferenceManager.getDefaultSharedPreferences(getActivity()).getInt("text_size_pref", 16); txt.setTextSize(textSize); txt.setTypeface(tf); LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); params.setMargins(15, 10, 15, 0); txt.setLayoutParams(params); lay.addView(txt); }
From source file:com.heath_bar.tvdb.SeriesOverview.java
/** Populate the GUI with the episode information */ private void PopulateStuffPartTwo() { // Populate the next/last episodes TvEpisode last = episodeList.getLastAired(); TvEpisode next = episodeList.getNextAired(); SpannableString text = null;//w ww. ja v a 2 s .co m TextView richTextView = (TextView) findViewById(R.id.last_episode); if (last == null) { text = new SpannableString("Last Episode: unknown"); } else { text = new SpannableString( "Last Episode: " + last.getName() + " (" + DateUtil.toString(last.getAirDate()) + ")"); NonUnderlinedClickableSpan clickableSpan = new NonUnderlinedClickableSpan() { @Override public void onClick(View view) { episodeListener.onClick(view); } }; int start = 14; int end = start + last.getName().length(); text.setSpan(clickableSpan, start, end, 0); text.setSpan(new TextAppearanceSpan(this, R.style.episode_link), start, end, 0); text.setSpan(new AbsoluteSizeSpan((int) textSize, true), 0, text.length(), 0); richTextView.setId(last.getId()); richTextView.setMovementMethod(LinkMovementMethod.getInstance()); } richTextView.setText(text, BufferType.SPANNABLE); text = null; richTextView = (TextView) findViewById(R.id.next_episode); if (seriesInfo != null && seriesInfo.getStatus() != null && !seriesInfo.getStatus().equals("Ended")) { if (next == null) { text = new SpannableString("Next Episode: unknown"); } else { text = new SpannableString( "Next Episode: " + next.getName() + " (" + DateUtil.toString(next.getAirDate()) + ")"); NonUnderlinedClickableSpan clickableSpan = new NonUnderlinedClickableSpan() { @Override public void onClick(View view) { episodeListener.onClick(view); } }; int start = 14; int end = start + next.getName().length(); text.setSpan(clickableSpan, start, end, 0); text.setSpan(new TextAppearanceSpan(this, R.style.episode_link), start, end, 0); text.setSpan(new AbsoluteSizeSpan((int) textSize, true), 0, text.length(), 0); richTextView.setId(next.getId()); richTextView.setMovementMethod(LinkMovementMethod.getInstance()); } richTextView.setText(text, BufferType.SPANNABLE); } }