List of usage examples for android.text.style UnderlineSpan UnderlineSpan
public UnderlineSpan()
From source file:com.geecko.QuickLyric.fragment.LyricsViewFragment.java
@SuppressLint("SetTextI18n") public void update(Lyrics lyrics, View layout, boolean animation) { File musicFile = null;/* w w w.j a v a 2 s .com*/ Bitmap cover = null; if (PermissionsChecker.hasPermission(getActivity(), "android.permission.READ_EXTERNAL_STORAGE")) { musicFile = Id3Reader.getFile(getActivity(), lyrics.getOriginalArtist(), lyrics.getOriginalTrack()); cover = Id3Reader.getCover(getActivity(), lyrics.getArtist(), lyrics.getTitle()); } setCoverArt(cover, null); boolean artCellDownload = Integer.valueOf( PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("pref_artworks", "0")) == 0; if (cover == null) new CoverArtLoader().execute(lyrics, this.getActivity(), artCellDownload || OnlineAccessVerifier.isConnectedWifi(getActivity())); getActivity().findViewById(R.id.edit_tags_btn).setEnabled(true); getActivity().findViewById(R.id.edit_tags_btn) .setVisibility(musicFile == null || !musicFile.canWrite() || lyrics.isLRC() || Id3Reader.getLyrics(getActivity(), lyrics.getArtist(), lyrics.getTitle()) == null ? View.GONE : View.VISIBLE); TextSwitcher textSwitcher = ((TextSwitcher) layout.findViewById(R.id.switcher)); LrcView lrcView = (LrcView) layout.findViewById(R.id.lrc_view); View v = getActivity().findViewById(R.id.tracks_msg); if (v != null) ((ViewGroup) v.getParent()).removeView(v); TextView artistTV = (TextView) getActivity().findViewById(R.id.artist); TextView songTV = (TextView) getActivity().findViewById(R.id.song); final TextView id3TV = (TextView) layout.findViewById(R.id.source_tv); TextView writerTV = (TextView) layout.findViewById(R.id.writer_tv); TextView copyrightTV = (TextView) layout.findViewById(R.id.copyright_tv); RelativeLayout bugLayout = (RelativeLayout) layout.findViewById(R.id.error_msg); this.mLyrics = lyrics; if (SDK_INT >= ICE_CREAM_SANDWICH) beamLyrics(lyrics, this.getActivity()); new PresenceChecker().execute(this, new String[] { lyrics.getArtist(), lyrics.getTitle(), lyrics.getOriginalArtist(), lyrics.getOriginalTrack() }); if (lyrics.getArtist() != null) artistTV.setText(lyrics.getArtist()); else artistTV.setText(""); if (lyrics.getTitle() != null) songTV.setText(lyrics.getTitle()); else songTV.setText(""); if (lyrics.getCopyright() != null) { copyrightTV.setText("Copyright: " + lyrics.getCopyright()); copyrightTV.setVisibility(View.VISIBLE); } else { copyrightTV.setText(""); copyrightTV.setVisibility(View.GONE); } if (lyrics.getWriter() != null) { if (lyrics.getWriter().contains(",")) writerTV.setText("Writers:\n" + lyrics.getWriter()); else writerTV.setText("Writer:" + lyrics.getWriter()); writerTV.setVisibility(View.VISIBLE); } else { writerTV.setText(""); writerTV.setVisibility(View.GONE); } if (isActiveFragment) ((RefreshIcon) getActivity().findViewById(R.id.refresh_fab)).show(); EditText newLyrics = (EditText) getActivity().findViewById(R.id.edit_lyrics); if (newLyrics != null) newLyrics.setText(""); if (lyrics.getFlag() == Lyrics.POSITIVE_RESULT) { if (!lyrics.isLRC()) { textSwitcher.setVisibility(View.VISIBLE); lrcView.setVisibility(View.GONE); if (animation) textSwitcher.setText(Html.fromHtml(lyrics.getText())); else textSwitcher.setCurrentText(Html.fromHtml(lyrics.getText())); } else { textSwitcher.setVisibility(View.GONE); lrcView.setVisibility(View.VISIBLE); lrcView.setOriginalLyrics(lyrics); lrcView.setSourceLrc(lyrics.getText()); if (isActiveFragment) ((ControllableAppBarLayout) getActivity().findViewById(R.id.appbar)).expandToolbar(true); updateLRC(); } bugLayout.setVisibility(View.INVISIBLE); id3TV.setMovementMethod(LinkMovementMethod.getInstance()); if ("Storage".equals(lyrics.getSource())) { id3TV.setVisibility(View.VISIBLE); SpannableString text = new SpannableString(getString(R.string.from_id3)); text.setSpan(new UnderlineSpan(), 1, text.length() - 1, 0); id3TV.setText(text); id3TV.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((MainActivity) getActivity()).id3PopUp(id3TV); } }); } else { id3TV.setOnClickListener(null); id3TV.setVisibility(View.GONE); } mScrollView.post(new Runnable() { @Override public void run() { mScrollView.scrollTo(0, 0); //only useful when coming from localLyricsFragment mScrollView.smoothScrollTo(0, 0); } }); } else { textSwitcher.setText(""); textSwitcher.setVisibility(View.INVISIBLE); lrcView.setVisibility(View.INVISIBLE); bugLayout.setVisibility(View.VISIBLE); int message; int whyVisibility; if (lyrics.getFlag() == Lyrics.ERROR || !OnlineAccessVerifier.check(getActivity())) { message = R.string.connection_error; whyVisibility = TextView.GONE; } else { message = R.string.no_results; whyVisibility = TextView.VISIBLE; updateSearchView(false, lyrics.getTitle(), false); } TextView whyTextView = ((TextView) bugLayout.findViewById(R.id.bugtext_why)); ((TextView) bugLayout.findViewById(R.id.bugtext)).setText(message); whyTextView.setVisibility(whyVisibility); whyTextView.setPaintFlags(whyTextView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); id3TV.setVisibility(View.GONE); } stopRefreshAnimation(); getActivity().getIntent().setAction(""); getActivity().invalidateOptionsMenu(); }
From source file:com.juick.android.MessageMenu.java
protected void runActions() { if (!isDialogMode()) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); final CharSequence[] items = new CharSequence[menuActions.size()]; for (int j = 0; j < items.length; j++) { items[j] = menuActions.get(j).title; }/* w w w. j a va 2 s . com*/ builder.setItems(items, this); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { ColorsTheme.ColorTheme colorTheme = JuickMessagesAdapter.getColorTheme(activity); ColorDrawable divider = new ColorDrawable( colorTheme.getColor(ColorsTheme.ColorKey.COMMON_BACKGROUND, 0xFFFFFFFF)); alertDialog.getListView().setDivider(divider); alertDialog.getListView().setDividerHeight(1); } }); alertDialog.show(); final ListAdapter adapter = alertDialog.getListView().getAdapter(); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity); float menuFontScale = 1; try { menuFontScale = Float.parseFloat(sp.getString("menuFontScale", "1.0")); } catch (Exception e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } final boolean compressedMenu = sp.getBoolean("compressedMenu", false); final boolean singleLineMenu = sp.getBoolean("singleLineMenu", false); final float finalMenuFontScale = menuFontScale; final int screenHeight = activity.getWindow().getWindowManager().getDefaultDisplay().getHeight(); alertDialog.getListView().setAdapter(new ListAdapter() { @Override public boolean areAllItemsEnabled() { return adapter.areAllItemsEnabled(); } @Override public boolean isEnabled(int position) { return adapter.isEnabled(position); } @Override public void registerDataSetObserver(DataSetObserver observer) { adapter.registerDataSetObserver(observer); } @Override public void unregisterDataSetObserver(DataSetObserver observer) { adapter.unregisterDataSetObserver(observer); } @Override public int getCount() { return items.length; } @Override public Object getItem(int position) { return adapter.getItem(position); } @Override public long getItemId(int position) { return adapter.getItemId(position); } @Override public boolean hasStableIds() { return adapter.hasStableIds(); } @Override public View getView(int position, View convertView, ViewGroup parent) { View retval = adapter.getView(position, null, parent); if (retval instanceof TextView) { TextView tv = (TextView) retval; if (compressedMenu) { int minHeight = (int) ((screenHeight * 0.7) / getCount()); tv.setMinHeight(minHeight); tv.setMinimumHeight(minHeight); } if (singleLineMenu) { tv.setSingleLine(true); tv.setEllipsize(TextUtils.TruncateAt.MIDDLE); } tv.setTextSize(22 * finalMenuFontScale); } return retval; } @Override public int getItemViewType(int position) { return adapter.getItemViewType(position); } @Override public int getViewTypeCount() { return adapter.getViewTypeCount(); } @Override public boolean isEmpty() { return adapter.isEmpty(); } }); } else { AlertDialog.Builder builder = new AlertDialog.Builder( new ContextThemeWrapper(activity, R.style.Theme_Sherlock)); View dialogView = activity.getLayoutInflater().inflate(R.layout.message_menu2, null); builder.setView(dialogView); builder.setCancelable(true); int width = activity.getWindowManager().getDefaultDisplay().getWidth(); View scrollView = dialogView.findViewById(R.id.scrollView); scrollView.getLayoutParams().width = (int) (width * 0.90); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { //MainActivity.restyleChildrenOrWidget(alertDialog.getWindow().getDecorView()); } }); TextView messageNo = (TextView) dialogView.findViewById(R.id.message_no); messageNo.setText(listSelectedItem.getDisplayMessageNo()); Spinner openUrl = (Spinner) dialogView.findViewById(R.id.open_url); Button singleURL = (Button) dialogView.findViewById(R.id.single_url); if (urls != null && urls.size() == 1) { singleURL.setVisibility(View.VISIBLE); openUrl.setVisibility(View.GONE); SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(urls.get(0)); sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); singleURL.setText(sb); singleURL.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); launchURL(listSelectedItem.getMID(), urls.get(0)); } }); } else if (urls != null && urls.size() > 0) { singleURL.setVisibility(View.GONE); openUrl.setVisibility(View.VISIBLE); openUrl.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position != 0) { alertDialog.dismiss(); launchURL(listSelectedItem.getMID(), urls.get(position)); } } @Override public void onNothingSelected(AdapterView<?> parent) { //To change body of implemented methods use File | Settings | File Templates. } }); urls.add(0, activity.getString(R.string.ClickToSelectURL)); openUrl.setAdapter(new BaseAdapter() { @Override public int getCount() { return urls.size(); } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { View rowView = activity.getLayoutInflater().inflate(android.R.layout.simple_list_item_1, null); TextView textView = (TextView) rowView.findViewById(android.R.id.text1); textView.setSingleLine(false); textView.setMaxLines(5); SpannableStringBuilder sb = new SpannableStringBuilder(); sb.append(urls.get(position)); if (position == 0) { textView.setTextColor(0xFF808080); } else { sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } textView.setText(sb); return rowView; } }); } else { openUrl.setVisibility(View.GONE); singleURL.setVisibility(View.GONE); } final String UName = listSelectedItem.User.UName; View recommendMessage = dialogView.findViewById(R.id.recommend_message); View deleteMessage = dialogView.findViewById(R.id.delete_message); View saveMessage = dialogView.findViewById(R.id.save_message); View unsaveMessage = dialogView.findViewById(R.id.unsave_message); //View subscribeUser = dialogView.findViewById(R.id.subscribe_user); View subscribeMessage = dialogView.findViewById(R.id.subscribe_message); //View unsubscribeUser = dialogView.findViewById(R.id.unsubscribe_user); View unsubscribeMessage = dialogView.findViewById(R.id.unsubscribe_message); View translateMessage = dialogView.findViewById(R.id.translate_message); View shareMessage = dialogView.findViewById(R.id.share_message); //View blacklistUser = dialogView.findViewById(R.id.blacklist_user); //View filterUser = dialogView.findViewById(R.id.filter_user); //View userBlog = dialogView.findViewById(R.id.user_blog); //View userStats = dialogView.findViewById(R.id.user_stats); View openMessageInBrowser = dialogView.findViewById(R.id.open_message_in_browser); Button userCenter = (Button) dialogView.findViewById(R.id.user_center); if (null == dialogView.findViewById(R.id.column_3)) { // only for portrait userCenter.setText("@" + listSelectedItem.User.UName + " " + userCenter.getText()); } unsubscribeMessage.setEnabled(listSelectedItem.getRID() == 0); subscribeMessage.setEnabled(listSelectedItem.getRID() == 0); unsaveMessage.setEnabled(listSelectedItem.getRID() == 0); recommendMessage.setEnabled(listSelectedItem.getRID() == 0); if (UName.equalsIgnoreCase(JuickAPIAuthorizer.getJuickAccountName(activity.getApplicationContext()))) { recommendMessage.setVisibility(View.GONE); } else { deleteMessage.setVisibility(View.GONE); } if (messagesSource instanceof SavedMessagesSource) { saveMessage.setVisibility(View.GONE); } else { unsaveMessage.setVisibility(View.GONE); } recommendMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionRecommendMessage(); } }); deleteMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionDeleteMessage(); } }); saveMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionSaveMessage(); } }); unsaveMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUnsaveMessage(); } }); // subscribeUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionSubscribeUser(); // } // }); subscribeMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionSubscribeMessage(); } }); // unsubscribeUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUnsubscribeUser(); // } // }); unsubscribeMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUnsubscribeMessage(); } }); translateMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionTranslateMessage(); } }); shareMessage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionShareMessage(); } }); // blacklistUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionBlacklistUser(); // } // }); // filterUser.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionFilterUser(UName); // } // }); // userBlog.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUserBlog(); // } // }); // userStats.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View v) { // alertDialog.dismiss(); // actionUserStats(); // } // }); openMessageInBrowser.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionOpenMessageInBrowser(); } }); userCenter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); actionUserCenter(); } }); completeInitDialogMode(alertDialog, dialogView); alertDialog.show(); } }
From source file:com.nttec.everychan.ui.presentation.HtmlParser.java
private static void endSpan(SpannableStringBuilder text, ThemeColors colors, boolean openSpoilers) { int len = text.length(); Object obj = getLast(text, Span.class); int where = text.getSpanStart(obj); text.removeSpan(obj);//from w w w . ja v a2 s .c o m if (where != len) { Span s = (Span) obj; if (s.mStyle != null) { List<Object> styleSpans = parseStyleAttributes(s.mStyle); for (Object span : styleSpans) { text.setSpan(span, where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } if (colors != null && s.mIsAibquote) { text.setSpan(new ForegroundColorSpan(colors.quoteForeground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (colors != null && s.mIsAibspoiler) { if (openSpoilers) { text.setSpan(new ForegroundColorSpan(colors.spoilerForeground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); text.setSpan(new BackgroundColorSpan(colors.spoilerBackground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else { text.setSpan(new SpoilerSpan(colors.spoilerForeground, colors.spoilerBackground), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } if (s.mIsUnderline) { text.setSpan(new UnderlineSpan(), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } if (s.mIsStrike) { text.setSpan(new StrikethroughSpan(), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
From source file:com.atwal.wakeup.battery.util.Utilities.java
public static SpannableString highlightKeywords(int color, String text, String keywords, boolean actionFirstMatch) { if (text != null && keywords != null && text.trim().length() == keywords.trim().length()) { return SpannableString.valueOf(text.trim()); }/*w ww . jav a2 s. c o m*/ SpannableString s = new SpannableString(text); Pattern p = Pattern.compile(keywords, Pattern.LITERAL); Matcher m = p.matcher(s); while (m.find()) { int end = m.end(); try { if (s.charAt(end) != ' ') { s.setSpan(new UnderlineSpan(), end, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { s.setSpan(new UnderlineSpan(), end + 1, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } catch (Exception e) { e.printStackTrace(); } if (actionFirstMatch) { break; } } return s; }
From source file:org.miaowo.miaowo.util.Html.java
private void handleEndTag(String tag) { if (tag.equalsIgnoreCase("br")) { handleBr(mSpannableStringBuilder); } else if (tag.equalsIgnoreCase("p")) { endCssStyle(mSpannableStringBuilder); endBlockElement(mSpannableStringBuilder); } else if (tag.equalsIgnoreCase("ul")) { endBlockElement(mSpannableStringBuilder); } else if (tag.equalsIgnoreCase("li")) { endLi(mSpannableStringBuilder);/*www . ja v a2s .c o m*/ } else if (tag.equalsIgnoreCase("div")) { endBlockElement(mSpannableStringBuilder); } else if (tag.equalsIgnoreCase("span")) { endCssStyle(mSpannableStringBuilder); } else if (tag.equalsIgnoreCase("strong")) { end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD)); } else if (tag.equalsIgnoreCase("b")) { end(mSpannableStringBuilder, Bold.class, new StyleSpan(Typeface.BOLD)); } else if (tag.equalsIgnoreCase("em")) { end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC)); } else if (tag.equalsIgnoreCase("cite")) { end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC)); } else if (tag.equalsIgnoreCase("dfn")) { end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC)); } else if (tag.equalsIgnoreCase("i")) { end(mSpannableStringBuilder, Italic.class, new StyleSpan(Typeface.ITALIC)); } else if (tag.equalsIgnoreCase("big")) { end(mSpannableStringBuilder, Big.class, new RelativeSizeSpan(1.25f)); } else if (tag.equalsIgnoreCase("small")) { end(mSpannableStringBuilder, Small.class, new RelativeSizeSpan(0.8f)); } else if (tag.equalsIgnoreCase("font")) { endFont(mSpannableStringBuilder); } else if (tag.equalsIgnoreCase("blockquote")) { endBlockquote(mSpannableStringBuilder); } else if (tag.equalsIgnoreCase("tt")) { end(mSpannableStringBuilder, Monospace.class, new TypefaceSpan("monospace")); } else if (tag.equalsIgnoreCase("a")) { endA(mSpannableStringBuilder); } else if (tag.equalsIgnoreCase("u")) { end(mSpannableStringBuilder, Underline.class, new UnderlineSpan()); } else if (tag.equalsIgnoreCase("del")) { end(mSpannableStringBuilder, Strikethrough.class, new StrikethroughSpan()); } else if (tag.equalsIgnoreCase("s")) { end(mSpannableStringBuilder, Strikethrough.class, new StrikethroughSpan()); } else if (tag.equalsIgnoreCase("strike")) { end(mSpannableStringBuilder, Strikethrough.class, new StrikethroughSpan()); } else if (tag.equalsIgnoreCase("sup")) { end(mSpannableStringBuilder, Super.class, new SuperscriptSpan()); } else if (tag.equalsIgnoreCase("sub")) { end(mSpannableStringBuilder, Sub.class, new SubscriptSpan()); } else if (tag.length() == 2 && Character.toLowerCase(tag.charAt(0)) == 'h' && tag.charAt(1) >= '1' && tag.charAt(1) <= '6') { endHeading(mSpannableStringBuilder); } else if (mTagHandler != null) { mTagHandler.handleTag(false, tag, mSpannableStringBuilder, mReader); } }
From source file:com.juick.android.JuickMessagesAdapter.java
private static void setStyleSpans(SpannableStringBuilder ssb, int ssbOffset, Object what, String styleChar) { String txt;/*from w w w .j a va 2s .c o m*/ txt = ssb.subSequence(ssbOffset, ssb.length()).toString(); txt = " " + txt + " "; ssbOffset -= 1; // int scan = 0; int cnt = 0; while (cnt++ < 20) { // don't need bugs in production. int ix = txt.indexOf(styleChar, scan); if (ix < 0) break; if (" \n".indexOf(txt.charAt(ix - 1)) != -1) { int ix2 = txt.indexOf(styleChar, ix + 1); if (ix2 < 0) break; if (" \n".indexOf(txt.charAt(ix2 + 1)) == -1 // not ends with space || txt.substring(ix, ix2).indexOf("\n") != -1) { // spans several lines scan = ix2; // not ok continue; } else { CharacterStyle span = null; CharacterStyle span2 = null; // found needed stuff if (what instanceof Integer && (((Integer) what) == Typeface.BOLD)) { span = new StyleSpan(Typeface.BOLD); if (helvNueFonts) { span2 = new CustomTypefaceSpan("", JuickAdvancedApplication.helvNueBold); } } if (what instanceof Integer && (((Integer) what) == Typeface.ITALIC)) { span = new StyleSpan(Typeface.ITALIC); } if (what == UnderlineSpan.class) { span = new UnderlineSpan(); } if (span != null && ix2 - ix > 1) { ssb.delete(ssbOffset + ix, ssbOffset + ix + 1); // delete styling char txt = stringDelete(txt, ix, ix + 1); ix2--; // moves, too ssb.delete(ssbOffset + ix2, ssbOffset + ix2 + 1); // second char deleted txt = stringDelete(txt, ix2, ix2 + 1); ssb.setSpan(span, ssbOffset + ix, ssbOffset + ix2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); if (span2 != null) { ssb.setSpan(span2, ssbOffset + ix, ssbOffset + ix2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } scan = ix2; } } } }
From source file:org.sirimangalo.meditationplus.ActivityMain.java
private void populateOnline(JSONArray onlines) { if (onlines.length() == 0) { onlineList.setVisibility(View.GONE); return;//from ww w . j a va 2 s. c om } onlineList.setVisibility(View.VISIBLE); ArrayList<JSONObject> onlineArray = new ArrayList<JSONObject>(); ArrayList<String> onlineNamesArray = new ArrayList<String>(); // collect into array for (int i = 0; i < onlines.length(); i++) { try { JSONObject a = onlines.getJSONObject(i); onlineArray.add(a); onlineNamesArray.add(a.getString("username")); } catch (JSONException e) { e.printStackTrace(); } } String text = getString(R.string.online) + " "; // add spans int pos = text.length(); // start after "Online: " text += TextUtils.join(", ", onlineNamesArray); Spannable span = new SpannableString(text); span.setSpan(new StyleSpan(Typeface.BOLD), 0, pos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // bold the "Online: " Drawable android = context.getResources().getDrawable(R.drawable.android); android.setBounds(0, 0, 48, 32); for (JSONObject oneOnA : onlineArray) { try { final String oneOn = oneOnA.getString("username"); int end = pos + oneOn.length(); boolean isMed = false; for (int j = 0; j < jsonList.length(); j++) { JSONObject user = jsonList.getJSONObject(j); String username = user.getString("username"); if (username.equals(oneOn)) isMed = true; } if (oneOnA.getString("source").equals("android")) { ImageSpan image = new ImageSpan(android, ImageSpan.ALIGN_BASELINE); span.setSpan(image, pos - 1, pos, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } ClickableSpan clickable = new ClickableSpan() { @Override public void onClick(View widget) { showProfile(oneOn); } }; span.setSpan(clickable, pos, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new UnderlineSpan() { public void updateDrawState(TextPaint tp) { tp.setUnderlineText(false); } }, pos, end, 0); span.setSpan(new ForegroundColorSpan(isMed ? 0xFF009900 : 0xFFFF9900), pos, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); pos += oneOn.length() + 2; } catch (JSONException e) { e.printStackTrace(); } } onlineList.setText(span); onlineList.setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:com.ichi2.anki.AbstractFlashcardViewer.java
protected void updateScreenCounts() { if (mCurrentCard == null) { return;//from w w w . j a v a2s. c o m } try { String[] title = getCol().getDecks().get(mCurrentCard.getDid()).getString("name").split("::"); getSupportActionBar().setTitle(title[title.length - 1]); } catch (JSONException e) { throw new RuntimeException(e); } int[] counts = mSched.counts(mCurrentCard); int eta = mSched.eta(counts, false); getSupportActionBar() .setSubtitle(getResources().getQuantityString(R.plurals.reviewer_window_title, eta, eta)); SpannableString newCount = new SpannableString(String.valueOf(counts[0])); SpannableString lrnCount = new SpannableString(String.valueOf(counts[1])); SpannableString revCount = new SpannableString(String.valueOf(counts[2])); if (mPrefHideDueCount) { revCount = new SpannableString("???"); } switch (mSched.countIdx(mCurrentCard)) { case Card.TYPE_NEW: newCount.setSpan(new UnderlineSpan(), 0, newCount.length(), 0); break; case Card.TYPE_LRN: lrnCount.setSpan(new UnderlineSpan(), 0, lrnCount.length(), 0); break; case Card.TYPE_REV: revCount.setSpan(new UnderlineSpan(), 0, revCount.length(), 0); break; } mTextBarNew.setText(newCount); mTextBarLearn.setText(lrnCount); mTextBarReview.setText(revCount); }
From source file:im.vector.activity.VectorRoomActivity.java
/** * Refresh the notifications area.// w w w. java 2 s .c o m */ private void refreshNotificationsArea() { // sanity check // might happen when the application is logged out if ((null == mSession.getDataHandler()) || (null == mRoom)) { return; } int iconId = -1; int textColor = -1; boolean isAreaVisible = false; SpannableString text = new SpannableString(""); boolean hasUnsentEvent = false; // remove any listeners mNotificationTextView.setOnClickListener(null); mNotificationIconImageView.setOnClickListener(null); // no network if (!Matrix.getInstance(this).isConnected()) { isAreaVisible = true; iconId = R.drawable.error; textColor = R.color.vector_fuchsia_color; text = new SpannableString(getResources().getString(R.string.room_offline_notification)); } else { Collection<Event> undeliveredEvents = mSession.getDataHandler().getStore() .getUndeliverableEvents(mRoom.getRoomId()); if ((null != undeliveredEvents) && (undeliveredEvents.size() > 0)) { hasUnsentEvent = true; isAreaVisible = true; iconId = R.drawable.error; String part1 = getResources().getString(R.string.room_unsent_messages_notification); String part2 = getResources().getString(R.string.room_prompt_resent); text = new SpannableString(part1 + " " + part2); text.setSpan(new UnderlineSpan(), part1.length() + 1, part1.length() + part2.length() + 1, 0); textColor = R.color.vector_fuchsia_color; mNotificationTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mVectorMessageListFragment.resendUnsentMessages(); refreshNotificationsArea(); } }); } else if ((null != mIsScrolledToTheBottom) && (!mIsScrolledToTheBottom)) { isAreaVisible = true; int unreadCount = 0; RoomSummary summary = mRoom.getDataHandler().getStore().getSummary(mRoom.getRoomId()); if (null != summary) { unreadCount = mRoom.getDataHandler().getStore().eventsCountAfter(mRoom.getRoomId(), summary.getLatestReadEventId()); } if (unreadCount > 0) { iconId = R.drawable.newmessages; textColor = R.color.vector_fuchsia_color; if (unreadCount == 1) { text = new SpannableString( getResources().getString(R.string.room_new_message_notification)); } else { text = new SpannableString( getResources().getString(R.string.room_new_messages_notification, unreadCount)); } } else { iconId = R.drawable.scrolldown; textColor = R.color.vector_text_gray_color; if (!TextUtils.isEmpty(mLatestTypingMessage)) { text = new SpannableString(mLatestTypingMessage); } } mNotificationTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mVectorMessageListFragment.scrollToBottom(0); } }); mNotificationIconImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mVectorMessageListFragment.scrollToBottom(0); } }); } else if (!TextUtils.isEmpty(mLatestTypingMessage)) { isAreaVisible = true; iconId = R.drawable.vector_typing; text = new SpannableString(mLatestTypingMessage); textColor = R.color.vector_text_gray_color; } } if (TextUtils.isEmpty(mEventId)) { mNotificationsArea.setVisibility(isAreaVisible ? View.VISIBLE : View.INVISIBLE); } if ((-1 != iconId) && (-1 != textColor)) { mNotificationIconImageView.setImageResource(iconId); mNotificationTextView.setText(text); mNotificationTextView.setTextColor(getResources().getColor(textColor)); } // if (null != mResendUnsentMenuItem) { mResendUnsentMenuItem.setVisible(hasUnsentEvent); } if (null != mResendDeleteMenuItem) { mResendDeleteMenuItem.setVisible(hasUnsentEvent); } }
From source file:com.ichi2.anki2.Reviewer.java
private void updateScreenCounts() { if (mCurrentCard == null) { return;/*from w ww . j a va 2s . c o m*/ } try { String[] title = mSched.getCol().getDecks().get(mCurrentCard.getDid()).getString("name").split("::"); AnkiDroidApp.getCompat().setTitle(this, title[title.length - 1], mInvertedColors); } catch (JSONException e) { throw new RuntimeException(e); } int[] counts = mSched.counts(mCurrentCard); int eta = mSched.eta(counts, false); AnkiDroidApp.getCompat().setSubtitle(this, getResources().getQuantityString(R.plurals.reviewer_window_title, eta, eta), mInvertedColors); SpannableString newCount = new SpannableString(String.valueOf(counts[0])); SpannableString lrnCount = new SpannableString(String.valueOf(counts[1])); SpannableString revCount = new SpannableString(String.valueOf(counts[2])); if (mPrefHideDueCount) { revCount = new SpannableString("???"); } switch (mCurrentCard.getQueue()) { case Card.TYPE_NEW: newCount.setSpan(new UnderlineSpan(), 0, newCount.length(), 0); break; case Card.TYPE_LRN: lrnCount.setSpan(new UnderlineSpan(), 0, lrnCount.length(), 0); break; case Card.TYPE_REV: revCount.setSpan(new UnderlineSpan(), 0, revCount.length(), 0); break; } mTextBarRed.setText(newCount); mTextBarBlack.setText(lrnCount); mTextBarBlue.setText(revCount); }