List of usage examples for android.text.method LinkMovementMethod getInstance
public static MovementMethod getInstance()
From source file:com.limewoodmedia.nsdroid.fragments.IssuesFragment.java
@Override public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { root = inflater.inflate(R.layout.issues, null, false); list = (ListView) root.findViewById(R.id.issues_list); title = (TextView) root.findViewById(R.id.issues_title); title.setText(// ww w . j a va 2 s .com getResources().getString(R.string.issues_title, NationInfo.getInstance(getActivity()).getName())); ViewTreeObserver observer = title.getViewTreeObserver(); observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { list.setPadding(list.getPaddingLeft(), title.getHeight() - (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15, getResources().getDisplayMetrics()), list.getPaddingRight(), list.getPaddingBottom()); } }); text = (TextView) root.findViewById(R.id.issues_text); text.setVisibility(View.GONE); issues = new ArrayList<Issue>(); listAdapter = new ArrayAdapter<Issue>(context, 0, issues) { @Override public View getView(int position, View convertView, ViewGroup parent) { View view; TextView text; if (convertView == null) { view = inflater.inflate(R.layout.issue_list_item, null); text = (TextView) view.findViewById(R.id.issue_item); text.setMovementMethod(LinkMovementMethod.getInstance()); } else { view = convertView; text = (TextView) view.findViewById(R.id.issue_item); } Issue issue = getItem(position); String txt = "• <a href=\"com.limewoodMedia.nsdroid.issue://" + issue.id + "\">" + issue.name + "</a> "; text.setText(Html.fromHtml(txt)); return view; } }; list.setAdapter(listAdapter); return root; }
From source file:com.keylesspalace.tusky.LoginActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("lightTheme", false)) { setTheme(R.style.AppTheme_Light); }/*from w ww .j a v a 2 s . co m*/ setContentView(R.layout.activity_login); ButterKnife.bind(this); if (savedInstanceState != null) { domain = savedInstanceState.getString("domain"); clientId = savedInstanceState.getString("clientId"); clientSecret = savedInstanceState.getString("clientSecret"); } else { domain = null; clientId = null; clientSecret = null; } preferences = getSharedPreferences(getString(R.string.preferences_file_key), Context.MODE_PRIVATE); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onButtonClick(editText); } }); final Context context = this; whatsAnInstance.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog dialog = new AlertDialog.Builder(context).setMessage(R.string.dialog_whats_an_instance) .setPositiveButton(R.string.action_close, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).show(); TextView textView = (TextView) dialog.findViewById(android.R.id.message); textView.setMovementMethod(LinkMovementMethod.getInstance()); } }); }
From source file:com.wordpress.ebc81.rtl_ais_android.tools.DialogManager.java
/** * Add new dialogs here!/*from w w w.ja va 2 s. co m*/ * @param id * @param args * @return */ private Dialog createDialog(final dialogs id, final String[] args) { switch (id) { case DIAG_LIST_USB: return genUSBDeviceDialog(); case DIAG_ABOUT: final AlertDialog addd = new AlertDialog.Builder(getActivity()).setTitle(R.string.help) .setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).setMessage(Html.fromHtml(getString(R.string.help_info))).create(); try { addd.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface paramDialogInterface) { try { final TextView tv = (TextView) addd.getWindow().findViewById(android.R.id.message); if (tv != null) tv.setMovementMethod(LinkMovementMethod.getInstance()); } catch (Exception e) { } } }); } catch (Exception e) { } return addd; case DIAG_LICENSE: return new AlertDialog.Builder(getActivity()).setTitle("COPYING") .setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).setMessage(readWholeStream("COPYING")).create(); } return null; }
From source file:com.deliciousdroid.fragment.AddBookmarkFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); base = (FragmentBaseActivity) getActivity(); setHasOptionsMenu(true);//from w w w . j av a 2 s .c om mEditUrl = (EditText) getView().findViewById(R.id.add_edit_url); mEditDescription = (EditText) getView().findViewById(R.id.add_edit_description); mDescriptionProgress = (ProgressBar) getView().findViewById(R.id.add_description_progress); mEditNotes = (EditText) getView().findViewById(R.id.add_edit_notes); mEditTags = (MultiAutoCompleteTextView) getView().findViewById(R.id.add_edit_tags); mRecommendedTags = (TextView) getView().findViewById(R.id.add_recommended_tags); mRecommendedProgress = (ProgressBar) getView().findViewById(R.id.add_recommended_tags_progress); mPopularTags = (TextView) getView().findViewById(R.id.add_popular_tags); mPopularProgress = (ProgressBar) getView().findViewById(R.id.add_popular_tags_progress); mPrivate = (CompoundButton) getView().findViewById(R.id.add_edit_private); mRecommendedTags.setMovementMethod(LinkMovementMethod.getInstance()); mPopularTags.setMovementMethod(LinkMovementMethod.getInstance()); if (base.mAccount != null) { String[] tagArray = new String[5]; tagArray = TagManager.GetTagsAsArray(base.mAccount.name, Tag.Name + " ASC", base).toArray(tagArray); ArrayAdapter<String> autoCompleteAdapter = new ArrayAdapter<String>(base, R.layout.autocomplete_view, tagArray); mEditTags.setAdapter(autoCompleteAdapter); mEditTags.setTokenizer(new SpaceTokenizer()); } mEditUrl.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { String url = mEditUrl.getText().toString(); if (mEditDescription.getText().toString().equals("")) { titleTask = new GetTitleTask().execute(url); } tagTask = new GetTagSuggestionsTask().execute(url); } } }); }
From source file:com.keylesspalace.tusky.util.LinkHelper.java
/** * Finds links, mentions, and hashtags in a piece of text and makes them clickable, associating * them with callbacks to notify when they're clicked. * * @param view the returned text will be put in * @param content containing text with mentions, links, or hashtags * @param mentions any '@' mentions which are known to be in the content * @param listener to notify about particular spans that are clicked *///from w w w . java 2s.co m public static void setClickableText(TextView view, Spanned content, @Nullable Status.Mention[] mentions, final LinkListener listener) { SpannableStringBuilder builder = new SpannableStringBuilder(content); URLSpan[] urlSpans = content.getSpans(0, content.length(), URLSpan.class); for (URLSpan span : urlSpans) { int start = builder.getSpanStart(span); int end = builder.getSpanEnd(span); int flags = builder.getSpanFlags(span); CharSequence text = builder.subSequence(start, end); if (text.charAt(0) == '#') { final String tag = text.subSequence(1, text.length()).toString(); ClickableSpan newSpan = new ClickableSpan() { @Override public void onClick(View widget) { listener.onViewTag(tag); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); } }; builder.removeSpan(span); builder.setSpan(newSpan, start, end, flags); } else if (text.charAt(0) == '@' && mentions != null && mentions.length > 0) { String accountUsername = text.subSequence(1, text.length()).toString(); /* There may be multiple matches for users on different instances with the same * username. If a match has the same domain we know it's for sure the same, but if * that can't be found then just go with whichever one matched last. */ String id = null; for (Status.Mention mention : mentions) { if (mention.localUsername.equalsIgnoreCase(accountUsername)) { id = mention.id; if (mention.url.contains(getDomain(span.getURL()))) { break; } } } if (id != null) { final String accountId = id; ClickableSpan newSpan = new ClickableSpan() { @Override public void onClick(View widget) { listener.onViewAccount(accountId); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); } }; builder.removeSpan(span); builder.setSpan(newSpan, start, end, flags); } } else { ClickableSpan newSpan = new CustomURLSpan(span.getURL()); builder.removeSpan(span); builder.setSpan(newSpan, start, end, flags); } } view.setText(builder); view.setLinksClickable(true); view.setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:com.kawakawaplanning.rssreader.Main.MainActivity.java
private void setSpannableString(View view) { String message = "????????????"; // ?? URL ?// www . j a va 2 s . c o m Map<String, String> map = new HashMap<String, String>(); map.put("", ""); // SpannableString ?? SpannableString ss = createSpannableString(message, map); // SpannableString ??? TextView textView = (TextView) view.findViewById(R.id.textView19); textView.setText(ss); textView.setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:com.pindroid.fragment.AddBookmarkFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); firstRun = savedInstanceState == null; setHasOptionsMenu(true);/*from ww w. ja va2 s.c o m*/ mEditUrl = ((FloatLabel) getView().findViewById(R.id.add_edit_url)).getEditText(); mEditDescription = ((FloatLabel) getView().findViewById(R.id.add_edit_description)).getEditText(); mDescriptionProgress = (ProgressBar) getView().findViewById(R.id.add_description_progress); mEditNotes = ((FloatLabel) getView().findViewById(R.id.add_edit_notes)).getEditText(); mEditTags = (MultiAutoCompleteTextView) ((FloatLabel) getView().findViewById(R.id.add_edit_tags)) .getEditText(); mRecommendedTags = (TextView) getView().findViewById(R.id.add_recommended_tags); mPopularTags = (TextView) getView().findViewById(R.id.add_popular_tags); mPrivate = (CompoundButton) getView().findViewById(R.id.add_edit_private); mToRead = (CompoundButton) getView().findViewById(R.id.add_edit_toread); mRecommendedTags.setMovementMethod(LinkMovementMethod.getInstance()); mPopularTags.setMovementMethod(LinkMovementMethod.getInstance()); if (username != null) { CursorAdapter autoCompleteAdapter = new TagAutoCompleteCursorAdapter(getActivity(), R.layout.autocomplete_view, null, new String[] { Tag.Name, Tag.Count }, new int[] { R.id.autocomplete_name, R.id.autocomplete_count }, 0); autoCompleteAdapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return TagManager.GetTagsAsCursor((constraint != null ? constraint.toString() : ""), username, Tag.Count + " DESC, " + Tag.Name + " ASC", getActivity()); } }); mEditTags.setAdapter(autoCompleteAdapter); mEditTags.setTokenizer(new SpaceTokenizer()); } mEditUrl.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { String url = mEditUrl.getText().toString().trim(); if (url != null && !url.equals("")) { if (mEditDescription.getText().toString().equals("")) { titleTask = new GetTitleTask().execute(url); } tagTask = new GetTagSuggestionsTask().execute(url); } } } }); }
From source file:com.ubergeek42.WeechatAndroid.adapters.ChatLinesAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { View retview; // The view to return TextView textview;/* w w w . j ava 2 s. c o m*/ boolean mustDrawReadMarker = getItemId(position) == buffer.readMarkerLine; // we only want to reuse TextViews, not the special lastLineRead view, // so force view recreation if (mustDrawReadMarker || convertView instanceof RelativeLayout) convertView = null; if (convertView == null) { if (mustDrawReadMarker) { retview = inflater.inflate(R.layout.chatview_line_read_marker, null); textview = (TextView) retview.findViewById(R.id.chatline_message); //noinspection deprecation retview.findViewById(R.id.separator).setBackgroundDrawable( new ColorDrawable(0xFF000000 | ColorScheme.get().chat_read_marker[0])); } else { textview = (TextView) inflater.inflate(R.layout.chatview_line, null); retview = textview; } textview.setTextColor(0xFF000000 | ColorScheme.get().defaul[0]); textview.setMovementMethod(LinkMovementMethod.getInstance()); } else { // convertview is only ever not null for the simple case textview = (TextView) convertView; retview = textview; } textview.setTextSize(P.textSize); Line line = (Line) getItem(position); textview.setText(line.spannable); textview.setTag(line); if (typeface != null) textview.setTypeface(typeface); return retview; }
From source file:org.bwgz.quotation.fragment.QuotationFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); Log.d(TAG, String.format("onCreateView - savedInstanceState: %s", savedInstanceState)); View view = inflater.inflate(R.layout.quotation_fragment, container, false); viewHolder = new ViewHolder(); viewHolder.quotation_text = (TextView) view.findViewById(R.id.quotation_text); viewHolder.spoken_by_character = (TextView) view.findViewById(R.id.spoken_by_character); viewHolder.source = (TextView) view.findViewById(R.id.source); viewHolder.author_name = (TextView) view.findViewById(R.id.author_name); viewHolder.author_image = (NetworkImageView) view.findViewById(R.id.author_image); viewHolder.author_description_citation_full = (TextView) view .findViewById(R.id.author_description_citation_full); viewHolder.author_description_short = (TextView) view.findViewById(R.id.author_description_short); viewHolder.author_description_full = (TextView) view.findViewById(R.id.author_description_full); viewHolder.author_notable_for = (TextView) view.findViewById(R.id.author_notable_for); viewHolder.author_description_layout = (LinearLayout) view.findViewById(R.id.author_description_layout); viewHolder.author_description_layout_short = (RelativeLayout) view .findViewById(R.id.author_description_layout_short); viewHolder.author_description_layout_full = (RelativeLayout) view .findViewById(R.id.author_description_layout_full); viewHolder.author_description_citation_full.setMovementMethod(LinkMovementMethod.getInstance()); viewHolder.author_description_layout.setOnClickListener(new ViewToggleOnClickListener( viewHolder.author_description_layout_short, viewHolder.author_description_layout_full)); if (viewHolder.author_image != null) { viewHolder.author_image.setDefaultImageResId(R.drawable.pick_image_holder); }/*w w w .ja va 2 s .co m*/ Bundle bundle = new Bundle(); bundle.putParcelable(LOADER_BUNDLE_URI, Quotation.withAppendedId(getPick().getId())); bundle.putStringArray(LOADER_BUNDLE_PROJECTION, new String[] { Quotation.QUOTATION, Quotation.SPOKEN_BY_CHARACTER, Source.NAME, Source.TYPE, BookmarkQuotation.BOOKMARK_ID }); quotationLoaderId = initLoader(this, bundle); bundle = new Bundle(); bundle.putParcelable(LOADER_BUNDLE_URI, QuotationPerson.withAppendedId(getPick().getId())); bundle.putStringArray(LOADER_BUNDLE_PROJECTION, new String[] { Person._ID, Person.NAME, Person.DESCRIPTION, Person.NOTABLE_FOR, Person.IMAGE_ID, Person.CITATION_PROVIDER, Person.CITATION_STATEMENT, Person.CITATION_URI }); authorLoaderId = initLoader(this, bundle); return view; }