List of usage examples for android.text.style ClickableSpan ClickableSpan
ClickableSpan
From source file:net.idlesoft.android.apps.github.activities.Repository.java
public void loadRepoInfo() { try {// ww w. ja v a 2 s . c om // TextView title = // (TextView)findViewById(R.id.tv_top_bar_title); // title.setText(m_jsonData.getString("name")); final TextView repo_name = (TextView) findViewById(R.id.tv_repository_info_name); repo_name.setText(mJson.getString("name")); repo_name.requestFocus(); final TextView repo_desc = (TextView) findViewById(R.id.tv_repository_info_description); repo_desc.setText(mJson.getString("description")); final TextView repo_owner = (TextView) findViewById(R.id.tv_repository_info_owner); repo_owner.setText(mJson.getString("owner")); final TextView repo_watcher_count = (TextView) findViewById(R.id.tv_repository_info_watchers); if (mJson.getInt("watchers") == 1) { repo_watcher_count.setText(mJson.getInt("watchers") + " watcher"); } else { repo_watcher_count.setText(mJson.getInt("watchers") + " watchers"); } final TextView repo_fork_count = (TextView) findViewById(R.id.tv_repository_info_forks); if (mJson.getInt("forks") == 1) { repo_fork_count.setText(mJson.getInt("forks") + " fork"); } else { repo_fork_count.setText(mJson.getInt("forks") + " forks"); } final TextView repo_website = (TextView) findViewById(R.id.tv_repository_info_website); if (mJson.getString("homepage") != "") { repo_website.setText(mJson.getString("homepage")); } else { repo_website.setText("N/A"); } /* Make the repository owner text link to his/her profile */ repo_owner.setMovementMethod(LinkMovementMethod.getInstance()); final Spannable spans = (Spannable) repo_owner.getText(); final ClickableSpan clickSpan = new ClickableSpan() { @Override public void onClick(final View widget) { final Intent i = new Intent(Repository.this, Profile.class); try { i.putExtra("username", mJson.getString("owner")); } catch (final JSONException e) { e.printStackTrace(); } startActivity(i); } }; spans.setSpan(clickSpan, 0, spans.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } catch (final JSONException e) { e.printStackTrace(); } ((Button) findViewById(R.id.btn_repository_info_branches)).setOnClickListener(new OnClickListener() { public void onClick(final View v) { final Intent intent = new Intent(Repository.this, BranchesList.class); intent.putExtra("repo_name", mRepositoryName); intent.putExtra("repo_owner", mRepositoryOwner); startActivity(intent); } }); ((Button) findViewById(R.id.btn_repository_info_issues)).setOnClickListener(new OnClickListener() { public void onClick(final View v) { final Intent intent = new Intent(Repository.this, Issues.class); intent.putExtra("repo_name", mRepositoryName); intent.putExtra("repo_owner", mRepositoryOwner); startActivity(intent); } }); ((Button) findViewById(R.id.btn_repository_info_network)).setOnClickListener(new OnClickListener() { public void onClick(final View v) { final Intent intent = new Intent(Repository.this, NetworkList.class); intent.putExtra("repo_name", mRepositoryName); intent.putExtra("username", mRepositoryOwner); startActivity(intent); } }); }
From source file:com.kawakawaplanning.rssreader.Main.MainActivity.java
private SpannableString createSpannableString(String message, Map<String, String> map) { SpannableString ss = new SpannableString(message); for (final Map.Entry<String, String> entry : map.entrySet()) { int start = 0; int end = 0; // ?? start, end ? Pattern pattern = Pattern.compile(entry.getKey()); Matcher matcher = pattern.matcher(message); while (matcher.find()) { start = matcher.start();/*w ww . j a v a2 s. co m*/ end = matcher.end(); break; } // SpannableString ??? ss.setSpan(new ClickableSpan() { @Override public void onClick(View textView) { Intent intent = new Intent(getApplicationContext(), OpenSourceLicenseActivity.class); startActivity(intent); } }, start, end, Spanned.SPAN_INCLUSIVE_INCLUSIVE); } return ss; }
From source file:org.onebusaway.android.ui.SituationDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle args = getArguments();//w w w.j a v a2 s. co m final String situationId = args.getString(ID); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setView(R.layout.situation) .setPositiveButton(R.string.hide, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int which) { Dialog dialog = (Dialog) dialogInterface; // Update the database to indicate that this alert has been hidden ObaContract.ServiceAlerts.insertOrUpdate(situationId, new ContentValues(), false, true); // Show the UNDO snackbar Snackbar.make(getActivity().findViewById(R.id.fragment_arrivals_list), R.string.alert_hidden_snackbar_text, Snackbar.LENGTH_SHORT) .setAction(R.string.alert_hidden_snackbar_action, new View.OnClickListener() { @Override public void onClick(View v) { ObaContract.ServiceAlerts.insertOrUpdate(situationId, new ContentValues(), false, false); if (mListener != null) { mListener.onUndo(); } } }).show(); dialog.dismiss(); if (mListener != null) { mListener.onDismiss(true); } } }).setNegativeButton(R.string.close, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); if (mListener != null) { mListener.onDismiss(false); } } }); final android.support.v7.app.AlertDialog dialog = builder.create(); dialog.show(); // Set the title, description, and URL (if provided) TextView title = (TextView) dialog.findViewById(R.id.alert_title); title.setText(args.getString(TITLE)); TextView desc = (TextView) dialog.findViewById(R.id.alert_description); desc.setText(args.getString(DESCRIPTION)); TextView urlView = (TextView) dialog.findViewById(R.id.alert_url); // Remove any previous clickable spans just to be safe UIUtils.removeAllClickableSpans(urlView); final String url = args.getString(URL); if (!TextUtils.isEmpty(url)) { urlView.setVisibility(View.VISIBLE); ClickableSpan urlClick = new ClickableSpan() { public void onClick(View v) { getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); } }; UIUtils.setClickableSpan(urlView, urlClick); } else { urlView.setVisibility(View.GONE); } // Update the database to indicate that this alert has been read ObaContract.ServiceAlerts.insertOrUpdate(args.getString(ID), new ContentValues(), true, null); return dialog; }
From source file:com.zd.vpn.fragments.AboutFragment.java
private void createPlayBuyOptions(ArrayList<String> ownedSkus, ArrayList<String> responseList) { try {//from www.ja v a2 s . c o m Vector<Pair<String, String>> gdonation = new Vector<Pair<String, String>>(); gdonation.add(new Pair<String, String>(getString(R.string.donatePlayStore), null)); HashMap<String, SkuResponse> responseMap = new HashMap<String, SkuResponse>(); for (String thisResponse : responseList) { JSONObject object = new JSONObject(thisResponse); responseMap.put(object.getString("productId"), new SkuResponse(object.getString("price"), object.getString("title"))); } for (String sku : donationSkus) if (responseMap.containsKey(sku)) gdonation.add( getSkuTitle(sku, responseMap.get(sku).title, responseMap.get(sku).price, ownedSkus)); String gmsTextString = ""; for (int i = 0; i < gdonation.size(); i++) { if (i == 1) gmsTextString += " "; else if (i > 1) gmsTextString += ", "; gmsTextString += gdonation.elementAt(i).first; } SpannableString gmsText = new SpannableString(gmsTextString); int lStart = 0; int lEnd = 0; for (Pair<String, String> item : gdonation) { lEnd = lStart + item.first.length(); if (item.second != null) { final String mSku = item.second; ClickableSpan cspan = new ClickableSpan() { @Override public void onClick(View widget) { triggerBuy(mSku); } }; gmsText.setSpan(cspan, lStart, lEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } lStart = lEnd + 2; // Account for ", " between items } if (gmsTextView != null) { gmsTextView.setText(gmsText); gmsTextView.setMovementMethod(LinkMovementMethod.getInstance()); gmsTextView.setVisibility(View.VISIBLE); } } catch (JSONException e) { VpnStatus.logException("Parsing Play Store IAP", e); } }
From source file:com.todoroo.astrid.actfm.ActFmLoginActivity.java
protected SpannableString getLinkStringWithCustomInterval(String base, String linkComponent, int start, int endOffset, final OnClickListener listener) { SpannableString link = new SpannableString(String.format("%s %s", //$NON-NLS-1$ base, linkComponent));/*from w ww. j a v a2s .c o m*/ ClickableSpan linkSpan = new ClickableSpan() { @Override public void onClick(View widget) { listener.onClick(widget); } @Override public void updateDrawState(TextPaint ds) { ds.setUnderlineText(true); ds.setColor(Color.rgb(68, 68, 68)); } }; link.setSpan(linkSpan, start, link.length() + endOffset, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return link; }
From source file:com.github.michalbednarski.intentslab.browser.ComponentInfoFragment.java
public static CharSequence dumpMetaData(final Context context, final String packageName, Bundle metaData) { FormattedTextBuilder text = new FormattedTextBuilder(); Context foreignContext = null; try {//from w w w . ja v a 2s . c o m foreignContext = context.createPackageContext(packageName, 0); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } if (metaData != null && !metaData.isEmpty()) { text.appendHeader(context.getString(R.string.metadata_header)); for (String key : metaData.keySet()) { Object value = metaData.get(key); if (value instanceof Integer) { // TODO resource? if (foreignContext != null) { text.appendValueNoNewLine(key, value.toString()); // Integers can point to resources final int resId = (Integer) value; if (resId == 0) { continue; } // [View as XML] link try { foreignContext.getResources().getXml(resId); text.appendClickable(context.getString(R.string.view_as_xml_resource), new ClickableSpan() { @Override public void onClick(View widget) { context.startActivity(new Intent(context, SingleFragmentActivity.class) .putExtra(SingleFragmentActivity.EXTRA_FRAGMENT, XmlViewerFragment.class.getName()) .putExtra(XmlViewerFragment.ARG_PACKAGE_NAME, packageName) .putExtra(XmlViewerFragment.ARG_RESOURCE_ID, resId)); } }); } catch (Resources.NotFoundException ignored) { } } // Other types } else if (value instanceof Float) { text.appendValueNoNewLine(key, value.toString() + (((Float) value) % 1f == 0f ? "" : " (float)")); } else if (value instanceof Boolean) { text.appendValueNoNewLine(key, value.toString()); } else if (value instanceof String) { text.appendValueNoNewLine(key, "\"" + value + "\""); } } } return text.getText(); }
From source file:com.ideascontest.navi.uask.MainQuestionAnswerAdapter.java
/** * OnBindViewHolder is called by the RecyclerView to display the data at the specified * position. In this method, we update the contents of the ViewHolder to display the correct * indices in the list for this particular position, using the "position" argument that is conveniently * passed into us./*w w w . ja v a2 s. co m*/ * * @param holder The ViewHolder which should be updated to represent the contents of the * item at the given position in the data set. * @param position The position of the item within the adapter's data set. */ @Override public void onBindViewHolder(QuestionTopAnswerHolder holder, int position) { Log.d(TAG, "#" + position); QuestionTopAnswerHolder questionTopAnswerHolder = (QuestionTopAnswerHolder) holder; final Context context = questionTopAnswerHolder.v.getContext(); Log.d(TAG, "Category" + _category); switch (_category) { case 0: case 1: case 2: case 3: case 4: { if (position == 0) { /* String infoText = (String) questionTopAnswerHolder.basicInfoText.getText(); int count = infoText.split("\n").length; int upperLimit = (count > 5) ? MainAnswerAdapter.ordinalIndexOf(infoText, "\n", 5) : 140; if (infoText.length() > 140 || count > 5) { infoText = infoText.substring(0, upperLimit) + "... " + "view more"; SpannableString sText = new SpannableString(infoText); ClickableSpan myClickableSpan = new ClickableSpan() { @Override public void onClick(View v) { Log.d("MainCanvas Category", "clickable Span"); //finish(); } }; int spanLowLimit = upperLimit + 4; int spanHighLimit = upperLimit + 13; sText.setSpan(myClickableSpan, spanLowLimit, spanHighLimit, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); sText.setSpan(new RelativeSizeSpan(0.75f), spanLowLimit, spanHighLimit, 0); sText.setSpan(new ForegroundColorSpan( questionTopAnswerHolder.v.getResources().getColor(R.color.primaryOrange)), spanLowLimit, spanHighLimit, 0); questionTopAnswerHolder.basicInfoText.setText(sText); questionTopAnswerHolder.basicInfoText.setMovementMethod(LinkMovementMethod.getInstance()); }*/ String infoText = (String) questionTopAnswerHolder.basicInfoText.getText(); int upperLimit = 150; if (infoText.length() > 150) { infoText = infoText.substring(0, upperLimit) + "... " + "view more"; SpannableString sText = new SpannableString(infoText); ClickableSpan myClickableSpan = new ClickableSpan() { @Override public void onClick(View v) { Log.d("Mainadapter Category", "clickable Span"); Intent intent = new Intent(context, ShowBasicInfo.class); intent.putExtra("category", _category); context.startActivity(intent);//finish(); } }; int spanLowLimit = upperLimit + 4; int spanHighLimit = upperLimit + 13; sText.setSpan(myClickableSpan, spanLowLimit, spanHighLimit, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); sText.setSpan(new RelativeSizeSpan(0.75f), spanLowLimit, spanHighLimit, 0); sText.setSpan( new ForegroundColorSpan( questionTopAnswerHolder.v.getResources().getColor(R.color.primaryOrange)), spanLowLimit, spanHighLimit, 0); questionTopAnswerHolder.basicInfoText.setText(sText); questionTopAnswerHolder.basicInfoText.setMovementMethod(LinkMovementMethod.getInstance()); } } else { populateDynamicUiElements(questionTopAnswerHolder, (position - 1)); } } break; case 5: { if (position == 0) { questionTopAnswerHolder.basicInfoText.setText("List of all non-categorical questions"); questionTopAnswerHolder.basicInfoText.setGravity(Gravity.CENTER | Gravity.BOTTOM); questionTopAnswerHolder.headingText.setVisibility(View.INVISIBLE); } else { populateDynamicUiElements(questionTopAnswerHolder, (position - 1)); } } break; case 6: { if (position == 0) { questionTopAnswerHolder.basicInfoText.setText("List of all questions asked by you."); questionTopAnswerHolder.basicInfoText.setGravity(Gravity.CENTER | Gravity.BOTTOM); questionTopAnswerHolder.headingText.setVisibility(View.INVISIBLE); } else { populateDynamicUiElements(questionTopAnswerHolder, (position - 1)); } } break; case 7: { if (position == 0) { questionTopAnswerHolder.basicInfoText.setText("List of all questions answered by you."); questionTopAnswerHolder.basicInfoText.setGravity(Gravity.CENTER | Gravity.BOTTOM); questionTopAnswerHolder.headingText.setVisibility(View.INVISIBLE); } else { populateDynamicUiElements(questionTopAnswerHolder, (position - 1)); } } break; case 8: { if (position == 0) { questionTopAnswerHolder.basicInfoText.setText( "All the private questions asked by your faculty students. Visible only to fellow faculty students"); questionTopAnswerHolder.basicInfoText.setGravity(Gravity.CENTER | Gravity.BOTTOM); questionTopAnswerHolder.headingText.setVisibility(View.INVISIBLE); } else { populateDynamicUiElements(questionTopAnswerHolder, (position - 1)); } } break; default: { populateDynamicUiElements(questionTopAnswerHolder, position); } break; } }
From source file:org.sirimangalo.meditationplus.AdapterCommit.java
@Override public View getView(final int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.list_item_commit, parent, false); final View shell = rowView.findViewById(R.id.detail_shell); rowView.setOnClickListener(new View.OnClickListener() { @Override//from w w w . j a va 2 s .c o m public void onClick(View view) { boolean visible = shell.getVisibility() == View.VISIBLE; shell.setVisibility(visible ? View.GONE : View.VISIBLE); context.setCommitVisible(position, !visible); } }); final JSONObject p = values.get(position); TextView title = (TextView) rowView.findViewById(R.id.title); TextView descV = (TextView) rowView.findViewById(R.id.desc); TextView defV = (TextView) rowView.findViewById(R.id.def); TextView usersV = (TextView) rowView.findViewById(R.id.users); TextView youV = (TextView) rowView.findViewById(R.id.you); try { if (p.getBoolean("open")) shell.setVisibility(View.VISIBLE); title.setText(p.getString("title")); descV.setText(p.getString("description")); String length = p.getString("length"); String time = p.getString("time"); final String cid = p.getString("cid"); String def = ""; boolean repeat = false; if (length.indexOf(":") > 0) { repeat = true; String[] lengtha = length.split(":"); def += lengtha[0] + " minutes walking and " + lengtha[1] + " minutes sitting"; } else def += length + " minutes total meditation"; String period = p.getString("period"); String day = p.getString("day"); if (period.equals("daily")) { if (repeat) def += " every day"; else def += " per day"; } else if (period.equals("weekly")) { if (repeat) def += " every " + dow[Integer.parseInt(day)]; else def += " per week"; } else if (period.equals("monthly")) { if (repeat) def += " on the " + day + (day.substring(day.length() - 1).equals("1") ? "st" : (day.substring(day.length() - 1).equals("2") ? "nd" : (day.substring(day.length() - 1).equals("3") ? "rd" : "th"))) + " day of the month"; else def += " per month"; } else if (period.equals("yearly")) { if (repeat) def += " on the " + day + (day.substring(day.length() - 1).equals("1") ? "st" : (day.substring(day.length() - 1).equals("2") ? "nd" : (day.substring(day.length() - 1).equals("3") ? "rd" : "th"))) + " day of the year"; else def += " per year"; } if (!time.equals("any")) { Calendar utc = Calendar.getInstance(TimeZone.getTimeZone("UTC")); utc.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time.split(":")[0])); utc.set(Calendar.MINUTE, Integer.parseInt(time.split(":")[1])); Calendar here = Calendar.getInstance(); here.setTimeInMillis(utc.getTimeInMillis()); int hours = here.get(Calendar.HOUR_OF_DAY); int minutes = here.get(Calendar.MINUTE); def += " at " + (time.length() == 4 ? "0" : "") + time.replace(":", "") + "h UTC <i>(" + (hours > 12 ? hours - 12 : hours) + ":" + ((minutes < 10 ? "0" : "") + minutes) + " " + (hours > 11 && hours < 24 ? "PM" : "AM") + " your time)</i>"; } defV.setText(Html.fromHtml(def)); JSONObject usersJ = p.getJSONObject("users"); ArrayList<String> committedArray = new ArrayList<String>(); // collect into array for (int i = 0; i < usersJ.names().length(); i++) { try { String j = usersJ.names().getString(i); String k = j; // if(j.equals(p.getString("creator"))) // k = "["+j+"]"; committedArray.add(k); } catch (JSONException e) { e.printStackTrace(); } } String text = context.getString(R.string.committed) + " "; // add spans int committed = -1; int pos = text.length(); // start after "Committed: " text += TextUtils.join(", ", committedArray); Spannable span = new SpannableString(text); span.setSpan(new StyleSpan(Typeface.BOLD), 0, pos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // bold the "Online: " for (int i = 0; i < committedArray.size(); i++) { try { final String oneCom = committedArray.get(i); String userCom = usersJ.getString(oneCom); //String userCom = usersJ.getString(oneCom.replace("[", "").replace("]", "")); //if(oneCom.replace("[","").replace("]","").equals(loggedUser)) if (oneCom.equals(loggedUser)) committed = Integer.parseInt(userCom); int end = pos + oneCom.length(); ClickableSpan clickable = new ClickableSpan() { @Override public void onClick(View widget) { context.showProfile(oneCom); } }; span.setSpan(clickable, pos, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new UnderlineSpan() { public void updateDrawState(TextPaint tp) { tp.setUnderlineText(false); } }, pos, end, 0); String color = Utils.makeRedGreen(Integer.parseInt(userCom), true); span.setSpan(new ForegroundColorSpan(Color.parseColor("#FF" + color)), pos, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); pos += oneCom.length() + 2; } catch (JSONException e) { e.printStackTrace(); } } usersV.setText(span); usersV.setMovementMethod(new LinkMovementMethod()); if (loggedUser != null && loggedUser.length() > 0) { LinearLayout bl = (LinearLayout) rowView.findViewById(R.id.commit_buttons); if (!usersJ.has(loggedUser)) { Button commitB = new Button(context); commitB.setId(R.id.commit_button); commitB.setText(R.string.commit); commitB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(); nvp.add(new BasicNameValuePair("full_update", "true")); context.doSubmit("commitform_" + cid, nvp, true); } }); bl.addView(commitB); } else { Button commitB = new Button(context); commitB.setId(R.id.uncommit_button); commitB.setText(R.string.uncommit); commitB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(); nvp.add(new BasicNameValuePair("full_update", "true")); context.doSubmit("uncommitform_" + cid, nvp, true); } }); bl.addView(commitB); } if (loggedUser.equals(p.getString("creator")) || context.isAdmin) { Button commitB2 = new Button(context); commitB2.setId(R.id.edit_commit_button); commitB2.setText(R.string.edit); commitB2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i = new Intent(context, ActivityCommit.class); i.putExtra("commitment", p.toString()); context.startActivity(i); } }); bl.addView(commitB2); Button commitB3 = new Button(context); commitB3.setId(R.id.uncommit_button); commitB3.setText(R.string.delete); commitB3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(); nvp.add(new BasicNameValuePair("full_update", "true")); context.doSubmit("delcommitform_" + cid, nvp, true); } }); bl.addView(commitB3); } } if (committed > -1) { int color = Color.parseColor("#FF" + Utils.makeRedGreen(committed, false)); rowView.setBackgroundColor(color); } if (committed != -1) { youV.setText(String.format(context.getString(R.string.you_commit_x), committed)); youV.setVisibility(View.VISIBLE); } } catch (Exception e) { e.printStackTrace(); } return rowView; }
From source file:eu.iescities.pilot.rovereto.roveretoexplorer.fragments.event.info.EventDetailInfoAdapter.java
@SuppressWarnings("deprecation") @Override/*from www . j a v a 2s . c o m*/ public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parentView) { final EventInfoParent parent = this.fragment.parents.get(groupPosition); final EventInfoChild child = parent.getChildren().get(childPosition); int itemType = getChildType(groupPosition, childPosition); Log.i("GROUPVIEW", "************ init child view!! ************ "); Log.i("GROUPVIEW", "COUNT: " + countChildViewCall); Log.i("GROUPVIEW", "CHILD TEXT: " + child.getText()); Log.i("GROUPVIEW", "CHILD TYPE: " + child.getType()); row = convertView; if (row == null) { // Inflate event_info_child_item.xml file for child rows LayoutInflater inflater = (LayoutInflater) this.fragment.context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = inflater.inflate(R.layout.event_info_child_item, parentView, false); eventChildViewHolder = new EventInfoChildViewHolder(); eventChildViewHolder.text = (TextView) row.findViewById(R.id.event_info_attribute_values); // eventChildViewHolder.imgSx = (ImageView) row // .findViewById(R.id.event_info_attribute_value_icon); eventChildViewHolder.imgsDx1 = (ImageView) row.findViewById(R.id.event_info_action1); eventChildViewHolder.divider = (View) row.findViewById(R.id.event_info_item_divider); //this will be added again when it will be possible to cancel/edit the single items // eventChildViewHolder.imgsDx2 = (ImageView) row // .findViewById(R.id.event_info_action2); // eventChildViewHolder.imgsDx3 = (ImageView) row // .findViewById(R.id.event_info_action3); row.setTag(eventChildViewHolder); } else { eventChildViewHolder = (EventInfoChildViewHolder) row.getTag(); } // Get event_info_child_item.xml file elements and set values if (child.getTextInBold()) eventChildViewHolder.text.setTypeface(null, Typeface.BOLD); else eventChildViewHolder.text.setTypeface(null, Typeface.NORMAL); if (!child.getText().contains("http")) { eventChildViewHolder.text.setText(child.getText()); } else { if (!child.getText().matches(fragment.getString(R.string.start_url))) { Log.i("GROUPVIEW", "make the text part clickable!!!"); //make the text part clickable int i1 = 0; int i2 = child.getName().length() - 1; eventChildViewHolder.text.setMovementMethod(LinkMovementMethod.getInstance()); eventChildViewHolder.text.setText(child.getName(), BufferType.SPANNABLE); //eventChildViewHolder.text.setAutoLinkMask(Linkify.WEB_URLS); //Linkify.addLinks(eventChildViewHolder.text, Linkify.WEB_URLS); //String s = "<a href=\" + child.getText() + \">Website</a>"; //eventChildViewHolder.text.setText(Html.fromHtml(s)); Spannable mySpannable = (Spannable) eventChildViewHolder.text.getText(); ClickableSpan myClickableSpan = new ClickableSpan() { @Override public void onClick(View widget) { // Toast.makeText(fragment.context, // "Open browser ofr url: " + child.getText(), // Toast.LENGTH_LONG).show(); String url = child.getText(); Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); fragment.context.startActivity(i); } }; // row.setFocusable(true); // row.setFocusableInTouchMode(true); mySpannable.setSpan(myClickableSpan, i1, i2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // eventChildViewHolder.text.setText(Html.fromHtml(child.getText())); // eventChildViewHolder.text.setMovementMethod(LinkMovementMethod.getInstance()); } else eventChildViewHolder.text.setText(child.getName()); } if (child.getName().equals("Description")) { //Log.i("EVENT", "EventDetailInfoAdapter --> set description to html!!"); eventChildViewHolder.text.setText(Html.fromHtml(child.getText())); eventChildViewHolder.text.setPadding(10, 10, 0, 0); } // set icon on the left side // if (child.getLeftIconId() != -1) { // Log.i("GROUPVIEW", "CHILD SX ICON ID: " + child.getLeftIconId()); // eventChildViewHolder.imgSx.setVisibility(View.VISIBLE); // eventChildViewHolder.imgSx.setImageResource(child.getLeftIconId()); // // Log.i("IMAGE", "IMG CHILD NAME: " // + child.getText()); // // Log.i("IMAGE", "IMG ICON WIDTH: " // + eventChildViewHolder.imgSx.getWidth()); // // } else { // Log.i("GROUPVIEW", "CHILD SX ICON -1"); // if ( (child.getName().equals("email")) || (child.getName().equals("tel")) ){ // Log.i("GROUPVIEW", "CHILD NAME: " + child.getName()); // eventChildViewHolder.imgSx.setVisibility(View.INVISIBLE); // eventChildViewHolder.text.setPadding(10, 0, 0, 0); // } // else{ // eventChildViewHolder.imgSx.setVisibility(View.GONE); // eventChildViewHolder.text.setPadding(10, 10, 0, 0); // } // // } // set icon on the left side if (child.getLeftIconId() != -1) { Log.i("GROUPVIEW", "CHILD SX ICON ID: " + child.getLeftIconId()); eventChildViewHolder.text.setCompoundDrawablesWithIntrinsicBounds(child.getLeftIconId(), 0, 0, 0); } else eventChildViewHolder.text.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); // set icons on the right side for the items of type 1 (telefono, email) if ((child.getRightIconIds() != null) && (child.getType() == 1)) { Log.i("GROUPVIEW", "CHILD DX1 ICON ID: " + child.getRightIconIds()[0]); eventChildViewHolder.text.setTypeface(null, Typeface.BOLD); eventChildViewHolder.imgsDx1.setVisibility(View.VISIBLE); eventChildViewHolder.imgsDx1.setImageResource(child.getRightIconIds()[0]); eventChildViewHolder.imgsDx1 .setOnClickListener(new ChildAddIconClickListener(this.fragment.context, child)); } else { Log.i("GROUPVIEW", "CHILD DX1 ICON NULL"); eventChildViewHolder.imgsDx1.setVisibility(View.INVISIBLE); } //set divider line height and color eventChildViewHolder.divider.setBackgroundColor(fragment.getResources().getColor(child.getDividerColor())); eventChildViewHolder.divider.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, child.getDividerHeight())); // set icons on the right side for the items of type 0 (single values) if ((child.getRightIconIds() != null) && (child.getType() == 0)) { Log.i("GROUPVIEW", "CHILD DX1 ICON ID: " + child.getRightIconIds()[0]); int iconsNumb = child.getRightIconIds().length; Log.i("GROUPVIEW", "ICON NUMMBER: " + iconsNumb); eventChildViewHolder.imgsDx1.setVisibility(View.VISIBLE); eventChildViewHolder.imgsDx1.setImageResource(child.getRightIconIds()[0]); eventChildViewHolder.imgsDx1 .setOnClickListener(new ChildActionIconClickListener(this.fragment.context, child)); //this will be added when cancel/edit for single item will be possible // eventChildViewHolder.imgsDx2.setVisibility(View.VISIBLE); // eventChildViewHolder.imgsDx2.setImageResource(child // .getRightIconIds()[1]); // if (iconsNumb == 3) // eventChildViewHolder.imgsDx3.setVisibility(View.VISIBLE); // eventChildViewHolder.imgsDx3.setImageResource(child // .getRightIconIds()[2]); } else { Log.i("GROUPVIEW", "CHILD DX1 ICON NULL"); eventChildViewHolder.imgsDx1.setVisibility(View.INVISIBLE); //this will be added when cancel/edit for single item will be possible // eventChildViewHolder.imgsDx2.setVisibility(View.INVISIBLE); // eventChildViewHolder.imgsDx3.setVisibility(View.INVISIBLE); } // Log.i("GROUPVIEW", "child view: group POS: " + groupPosition + "!!"); // Log.i("GROUPVIEW", "child view: child POS: " + childPosition + "!!"); countChildViewCall++; return row; }
From source file:com.vuze.android.remote.spanbubbles.SpanTags.java
public void setTagBubbles(final SpannableStringBuilder ss, String text, String token) { if (ss.length() > 0) { // hack to ensure descent is always added by TextView ss.append("\u200B"); }/*from w w w . j a v a2 s . co m*/ if (tvTags == null) { Log.e(TAG, "no tvTags"); return; } TextPaint p = tvTags.getPaint(); // Start and end refer to the points where the span will apply int tokenLen = token.length(); int base = 0; if (showIcon && tagDrawables == null) { createDrawTagables(); } while (true) { int start = text.indexOf(token, base); int end = text.indexOf(token, start + tokenLen); if (start < 0 || end < 0) { break; } base = end + tokenLen; final int fSpanStart = start; final int fSpanEnd = end + tokenLen; String id = text.substring(start + tokenLen, end); Map mapTag = null; try { long tagUID = Long.parseLong(id); mapTag = sessionInfo.getTag(tagUID); } catch (Throwable ignore) { } final String word = MapUtils.getMapString(mapTag, "name", "" + id); final Map fMapTag = mapTag; final DrawableTag imgDrawable = new DrawableTag(context, p, word, showIcon ? tagDrawables : null, mapTag, drawCount) { @Override public boolean isTagPressed() { if (!AndroidUtils.usesNavigationControl()) { return false; } int selectionEnd = tvTags.getSelectionEnd(); if (selectionEnd < 0) { return false; } int selectionStart = tvTags.getSelectionStart(); return selectionStart == fSpanStart && selectionEnd == fSpanEnd; } @Override public int getTagState() { if (listener == null) { return TAG_STATE_SELECTED; } return listener.getTagState(fMapTag, word); } }; if (countFontRatio > 0) { imgDrawable.setCountFontRatio(countFontRatio); } imgDrawable.setBounds(0, 0, imgDrawable.getIntrinsicWidth(), imgDrawable.getIntrinsicHeight()); // Log.d(TAG, "State=" + Arrays.toString(imgDrawable.getState())); if (listener != null && showIcon) { int tagState = listener.getTagState(mapTag, word); int[] state = makeState(tagState, mapTag == null, false); imgDrawable.setState(state); } ImageSpan imageSpan = new ImageSpan(imgDrawable, DynamicDrawableSpan.ALIGN_BASELINE) { @Override public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) { int size = super.getSize(paint, text, start, end, fm); int width = -1; if (tvTags.getLayoutParams().width == ViewGroup.LayoutParams.WRAP_CONTENT) { if (tvTags.getParent() instanceof ViewGroup) { width = ((ViewGroup) tvTags.getParent()).getWidth(); } } else { width = tvTags.getWidth(); } if (width <= 0) { return size; } return Math.min(size, width); } }; ss.setSpan(imageSpan, start, end + tokenLen, 0); if (listener != null) { ClickableSpan clickSpan = new ClickableSpan() { @Override public void onClick(View widget) { listener.tagClicked(fMapTag, word); if (AndroidUtils.hasTouchScreen()) { Selection.removeSelection((Spannable) tvTags.getText()); } widget.invalidate(); } }; ss.setSpan(clickSpan, start, end + tokenLen, 0); } } }