android.text.style.ImageSpan Java Examples
The following examples show how to use
android.text.style.ImageSpan.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SearchView.java From cathode with Apache License 2.0 | 6 votes |
@Override protected void onFinishInflate() { super.onFinishInflate(); inputView = findViewById(R.id.search_input); clearView = findViewById(R.id.search_clear); inputView.setOnKeyListener(inputKeyListener); inputView.addTextChangedListener(inputListener); SpannableStringBuilder ssb = new SpannableStringBuilder(" "); ssb.append(getResources().getString(R.string.action_search)); Drawable searchIcon = ContextCompat.getDrawable(getContext(), R.drawable.ic_action_search_24dp); int textSize = (int) (inputView.getTextSize() * 1.25); searchIcon.setBounds(0, 0, textSize, textSize); ssb.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); inputView.setHint(ssb); clearView.setOnClickListener(clearListener); clearView.setVisibility(inputView.getText().toString().isEmpty() ? INVISIBLE : VISIBLE); }
Example #2
Source File: Html.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private static void startImg(Editable text, Attributes attributes, Html.ImageGetter img) { String src = attributes.getValue("", "src"); Drawable d = null; if (img != null) { d = img.getDrawable(src); } if (d == null) { d = Resources.getSystem(). getDrawable(com.android.internal.R.drawable.unknown_image); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); } int len = text.length(); text.append("\uFFFC"); text.setSpan(new ImageSpan(d, src), len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }
Example #3
Source File: HtmlToSpannedConverter.java From HtmlCompat with Apache License 2.0 | 6 votes |
private void startImg(Editable text, Attributes attributes, HtmlCompat.ImageGetter img) { String src = attributes.getValue("", "src"); Drawable d = null; if (img != null) { d = img.getDrawable(src, attributes); } if (d == null) { Resources res = mContext.getResources(); d = res.getDrawable(R.drawable.unknown_image); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); } int len = text.length(); text.append("\uFFFC"); text.setSpan(new ImageSpan(d, src), len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }
Example #4
Source File: EmoticonsEditText.java From FlyWoo with Apache License 2.0 | 6 votes |
private CharSequence replace(String text) { try { SpannableString spannableString = new SpannableString(text); int start = 0; Pattern pattern = buildPattern(); Matcher matcher = pattern.matcher(text); while (matcher.find()) { String faceText = matcher.group(); String key = faceText.substring(1); BitmapFactory.Options options = new BitmapFactory.Options(); Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(), getContext().getResources().getIdentifier(key, "drawable", getContext().getPackageName()), options); ImageSpan imageSpan = new ImageSpan(getContext(), bitmap); int startIndex = text.indexOf(faceText, start); int endIndex = startIndex + faceText.length(); if (startIndex >= 0) spannableString.setSpan(imageSpan, startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); start = (endIndex - 1); } return spannableString; } catch (Exception e) { return text; } }
Example #5
Source File: SmileyParser.java From AcDisplay with GNU General Public License v2.0 | 6 votes |
/** * Adds ImageSpans to a CharSequence that replace textual emoticons such * as :-) with a graphical version. * * @param text A CharSequence possibly containing emoticons * @return A CharSequence annotated with ImageSpans covering any * recognized emoticons. */ public CharSequence addSmileySpans(@Nullable CharSequence text) { if (text == null) return null; SpannableStringBuilder builder = new SpannableStringBuilder(text); Matcher matcher = mPattern.matcher(text); while (matcher.find()) { int resId = mSmileyToRes.get(matcher.group()); int start = matcher.start(); int end = matcher.end(); Check.getInstance().isTrue(end > start); builder.setSpan(new ImageSpan(mContext, resId), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } return builder; }
Example #6
Source File: EditTextUtil.java From RxAndroidBootstrap with Apache License 2.0 | 6 votes |
/** * Sets the edittext's hint icon and text. * * @param editText * @param drawableResource * @param hintText */ public static void setSearchHintWithColorIcon(EditText editText, int drawableResource, int textColor, String hintText) { try { SpannableStringBuilder stopHint = new SpannableStringBuilder(" "); stopHint.append(hintText); // Add the icon as an spannable Drawable searchIcon = editText.getContext().getResources().getDrawable(drawableResource); Float rawTextSize = editText.getTextSize(); int textSize = (int) (rawTextSize * 1.25); searchIcon.setBounds(0, 0, textSize, textSize); stopHint.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // Set the new hint text editText.setHint(stopHint); //searchBox.setTextColor(Color.WHITE); editText.setHintTextColor(textColor); } catch (Exception e) { Log.e("EditTextUtil", e.getMessage(), e); } }
Example #7
Source File: MoonUtil.java From NIM_Android_UIKit with MIT License | 6 votes |
private static SpannableString replaceEmoticons(Context context, String value, float scale, int align) { if (TextUtils.isEmpty(value)) { value = ""; } SpannableString mSpannableString = new SpannableString(value); Matcher matcher = EmojiManager.getPattern().matcher(value); while (matcher.find()) { int start = matcher.start(); int end = matcher.end(); String emot = value.substring(start, end); Drawable d = getEmotDrawable(context, emot, scale); if (d != null) { ImageSpan span = new ImageSpan(d, align); mSpannableString.setSpan(span, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } return mSpannableString; }
Example #8
Source File: Html.java From tysq-android with GNU General Public License v3.0 | 6 votes |
private void startAudio(SpannableStringBuilder text, Attributes attributes, Html.ImageGetter imageGetter) { AudioInfo audioInfo = (AudioInfo) DECODE_MAP.get(MediaType.AUDIO).getData(); Drawable coverDrawable = null; if (imageGetter instanceof JerryImageGetter) { JerryImageGetter jerryImageGetter = (JerryImageGetter) imageGetter; jerryImageGetter.setType(MediaType.AUDIO); jerryImageGetter.setFileName(audioInfo.getTitle()); coverDrawable = jerryImageGetter.getDrawable(""); } ImageSpan imageSpan = new JerryAudioSpan(coverDrawable, audioInfo); int len = text.length(); text.append("\uFFFC"); text.setSpan(imageSpan, len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }
Example #9
Source File: VIPCountDownTimer.java From LLApp with Apache License 2.0 | 6 votes |
/** * 重写父类的initSpanData方法 * 通过number数组得到每块数值对应的自定义MikyouBackgroundSpan对象 * 然后通过MikyouBackgroundSpan对象定义每块数值的样式包括背景,边框,边框圆角样式,然后将这些对象加入到集合中去 * 通过nonNumber数组得到每个间隔的ForegroundColorSpan对象 * 然后通过这些对象就可以定义每个间隔块的样式,因为只定义了ForegroundColorSpan所以只能定义 * 每个间隔块的字体颜色,setmGapSpanColor方式也是供外部自由定制每个间隔的样式 * 实际上还可以定义其他的Span,同理实现也是很简单的。 * */ @Override public void initSpanData(String timeStr) { super.initSpanData(timeStr); vipNumbers = TimerUtils.getNumInTimerStr(timeStr);//得到每个数字注意不是每块数值,并加入数组 vipNonNumbers = TimerUtils.getNonNumInTimerStr(timeStr);//得到每个间隔字符,并加入到数组 for (int i=0;i<vipNumbers.length;i++){ for (int j=0;j<vipNumbers[i].toCharArray().length;j++){//因为需要得到每个数字所以还得遍历每块数值中的每个数字,所以需要二层循环 MikyouBackgroundSpan mSpan = new MikyouBackgroundSpan(mContext.getDrawable(mDrawableId), ImageSpan.ALIGN_BOTTOM); initBackSpanStyle(mSpan); mSpanList.add(mSpan); } } for (int i= 0; i<vipNonNumbers.length;i++){ ForegroundColorSpan mGapSpan = new ForegroundColorSpan(mGapSpanColor); mTextColorSpanList.add(mGapSpan); } }
Example #10
Source File: MoonUtil.java From NIM_Android_UIKit with MIT License | 6 votes |
public static void replaceEmoticons(Context context, Editable editable, int start, int count) { if (count <= 0 || editable.length() < start + count) return; CharSequence s = editable.subSequence(start, start + count); Matcher matcher = EmojiManager.getPattern().matcher(s); while (matcher.find()) { int from = start + matcher.start(); int to = start + matcher.end(); String emot = editable.subSequence(from, to).toString(); Drawable d = getEmotDrawable(context, emot, SMALL_SCALE); if (d != null) { ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM); editable.setSpan(span, from, to, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
Example #11
Source File: EditTextUtil.java From MVPAndroidBootstrap with Apache License 2.0 | 6 votes |
/** * Sets the edittext's hint icon and text. * * @param editText * @param drawableResource * @param hintText */ public static void setSearchHintWithColorIcon(EditText editText, int drawableResource, int textColor, String hintText) { try { SpannableStringBuilder stopHint = new SpannableStringBuilder(" "); stopHint.append(hintText); // Add the icon as an spannable Drawable searchIcon = editText.getContext().getResources().getDrawable(drawableResource); Float rawTextSize = editText.getTextSize(); int textSize = (int) (rawTextSize * 1.25); searchIcon.setBounds(0, 0, textSize, textSize); stopHint.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // Set the new hint text editText.setHint(stopHint); //searchBox.setTextColor(Color.WHITE); editText.setHintTextColor(textColor); } catch (Exception e) { Log.e("EditTextUtil", e.getMessage(), e); } }
Example #12
Source File: ExpressionUtil.java From styT with Apache License 2.0 | 6 votes |
/** * 替换表情 * * @param context * @param str * @return */ public static SpannableString getSpannableString(Context context, String str) { SpannableString spannableString = new SpannableString(str); String s = "\\[(.+?)\\]"; Pattern pattern = Pattern.compile(s, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(spannableString); while (matcher.find()) { String key = matcher.group(); int id = Expression.getIdAsName(key); if (id != 0) { Drawable drawable = context.getResources().getDrawable(id); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); ImageSpan imageSpan = new ImageSpan(drawable); spannableString.setSpan(imageSpan, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } return spannableString; }
Example #13
Source File: Util.java From UETool with MIT License | 6 votes |
private static List<Pair<String, Bitmap>> getTextViewImageSpanBitmap(TextView textView) { List<Pair<String, Bitmap>> bitmaps = new ArrayList<>(); try { CharSequence text = textView.getText(); if (text instanceof SpannedString) { Field mSpansField = Class.forName("android.text.SpannableStringInternal").getDeclaredField("mSpans"); mSpansField.setAccessible(true); Object[] spans = (Object[]) mSpansField.get(text); for (Object span : spans) { if (span instanceof ImageSpan) { bitmaps.add(new Pair<>("SpanBitmap", getDrawableBitmap(((ImageSpan) span).getDrawable()))); } } } } catch (Exception e) { e.printStackTrace(); } return bitmaps; }
Example #14
Source File: RichEditText.java From RichEditText with Apache License 2.0 | 6 votes |
/** * * @param bitmap * @param filePath * @param start * @param end */ public void addDefaultImage(String filePath,int start,int end) { Log.i("imgpath", filePath); String pathTag = "<img src=\"" + filePath + "\"/>"; SpannableString spanString = new SpannableString(pathTag); // 获取屏幕的宽高 Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.default_img); int paddingLeft = getPaddingLeft(); int paddingRight = getPaddingRight(); int bmWidth = bitmap.getWidth();//图片高度 int bmHeight = bitmap.getHeight();//图片宽度 int zoomWidth = getWidth() - (paddingLeft + paddingRight); int zoomHeight = (int) (((float)zoomWidth / (float)bmWidth) * bmHeight); Bitmap newBitmap = zoomImage(bitmap, zoomWidth,zoomHeight); ImageSpan imgSpan = new ImageSpan(mContext, newBitmap); spanString.setSpan(imgSpan, 0, pathTag.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); if(mEditable==null){ mEditable = this.getText(); // 获取edittext内容 } mEditable.delete(start, end);//删除 mEditable.insert(start, spanString); // 设置spanString要添加的位置 }
Example #15
Source File: PlatformPagerAdapter.java From citra_android with GNU General Public License v3.0 | 6 votes |
@Override public CharSequence getPageTitle(int position) { // Hax from https://guides.codepath.com/android/Google-Play-Style-Tabs-using-TabLayout#design-support-library // Apparently a workaround for TabLayout not supporting icons. // TODO This workaround will eventually not be necessary; switch to more legit methods when that is the case // TODO Also remove additional hax from styles.xml Drawable drawable = mContext.getResources().getDrawable(TAB_ICONS[position]); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BOTTOM); SpannableString sb = new SpannableString(" "); sb.setSpan(imageSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return sb; }
Example #16
Source File: CommentListActivity.java From NewFastFrame with Apache License 2.0 | 6 votes |
private SpannableStringBuilder getText(PublicPostBean bean) { SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(); SpannableString spannableString = new SpannableString("."); spannableString.setSpan(new ImageSpan(this, R.drawable.ic_location, DynamicDrawableSpan.ALIGN_BASELINE), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); String location = ""; if (bean.getLocation() != null) { LocationEvent mLocationEvent = BaseApplication.getAppComponent().getGson().fromJson(bean.getLocation(), LocationEvent.class); if (mLocationEvent.getCity().equals(mLocationEvent.getTitle())) { location = mLocationEvent.getTitle(); } else { location = mLocationEvent.getCity() + "." + mLocationEvent.getTitle(); } } spannableStringBuilder.append(TimeUtil.getRealTime(bean.getCreatedAt() == null ? bean.getUpdatedAt() : bean.getCreatedAt())).append(" ").append(spannableString).append(location); return spannableStringBuilder; }
Example #17
Source File: MainActivity.java From Study_Android_Demo with Apache License 2.0 | 6 votes |
private void startImg(SpannableStringBuilder text, String src, Html.ImageGetter img) { Drawable d = null; if (img != null) { d = img.getDrawable(src); } if (d == null) { d = getResources().getDrawable(R.mipmap.ic_launcher); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); } int len = text.length(); text.append("\uFFFC"); text.setSpan(new ImageSpan(d, src), len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }
Example #18
Source File: GifTextView.java From chatui with Apache License 2.0 | 6 votes |
/** * 对静态图片进行解析: * 创建一个SpanInfo对象,帧数设为1,按照下面的参数设置,最后不要忘记将SpanInfo对象添加进spanInfoList中, 否则不会显示 * * @param resourceId * @param start * @param end */ @SuppressWarnings("unused") private void parseBmp(int resourceId, int start, int end) { Bitmap bitmap = BitmapFactory.decodeResource(getContext() .getResources(), resourceId); ImageSpan imageSpan = new ImageSpan(getContext(), bitmap); SpanInfo spanInfo = new SpanInfo(); spanInfo.currentFrameIndex = 0; spanInfo.frameCount = 1; spanInfo.start = start; spanInfo.end = end; spanInfo.delay = 100; spanInfo.mapList.add(bitmap); spanInfoList.add(spanInfo); }
Example #19
Source File: DemoAdapter.java From styT with Apache License 2.0 | 6 votes |
/** * 替换表情 * * @param str * @param context * @return */ private SpannableString getSpannableString(String str, Context context) { SpannableString spannableString = new SpannableString(str); String s = "\\[(.+?)\\]"; Pattern pattern = Pattern.compile(s, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(spannableString); while (matcher.find()) { String key = matcher.group(); int id = Expression.getIdAsName(key); if (id != 0) { Drawable drawable = context.getResources().getDrawable(id); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); ImageSpan imageSpan = new ImageSpan(drawable); spannableString.setSpan(imageSpan, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } return spannableString; }
Example #20
Source File: EmoticonsTextView.java From FlyWoo with Apache License 2.0 | 6 votes |
private CharSequence replace(String text) { try { SpannableString spannableString = new SpannableString(text); int start = 0; Pattern pattern = buildPattern(); Matcher matcher = pattern.matcher(text); while (matcher.find()) { String faceText = matcher.group(); String key = faceText.substring(1); BitmapFactory.Options options = new BitmapFactory.Options(); Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(), getContext().getResources().getIdentifier(key, "drawable", getContext().getPackageName()), options); ImageSpan imageSpan = new ImageSpan(getContext(), bitmap); int startIndex = text.indexOf(faceText, start); int endIndex = startIndex + faceText.length(); if (startIndex >= 0) spannableString.setSpan(imageSpan, startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); start = (endIndex - 1); } return spannableString; } catch (Exception e) { return text; } }
Example #21
Source File: TagSpanGenerator.java From intra42 with Apache License 2.0 | 5 votes |
public void addTag(String text, @ColorInt int backgroundColor, @ColorInt int textColor) { ChipDrawable chip = ChipDrawable.createFromResource(context, R.xml.standalone_chip); // Use it as a Drawable however you want. chip.setText(text); chip.setChipBackgroundColor(ColorStateList.valueOf(backgroundColor)); chip.setBounds(0, 0, chip.getIntrinsicWidth(), (int) (chip.getIntrinsicHeight() * 0.75f)); ImageSpan imageSpan = new ImageSpan(chip); int length = stringBuilder.length(); stringBuilder.append(text); stringBuilder.setSpan(imageSpan, length, length + text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); }
Example #22
Source File: SearchResultAdapter.java From talk-android with MIT License | 5 votes |
public SearchResultAdapter(Context context, SearchListener listener) { this.context = context; this.listener = listener; originMembers = MemberRealm.getInstance().getNotRobotMemberWithCurrentThread(); if (originMembers == null) { originMembers = new ArrayList<>(); } int pMe = -1; for (int i = 0; i < originMembers.size(); i++) { if (BizLogic.isMe(originMembers.get(i).get_id())) { pMe = i; break; } } if (pMe != -1) { originMembers.remove(pMe); } originRooms = RoomRealm.getInstance().getRoomOnNotArchivedWithCurrentThread(); if (originRooms == null) { originRooms = new ArrayList<>(); } members = new ArrayList<>(); rooms = new ArrayList<>(); messages = new ArrayList<>(); rows = new ArrayList<>(); arrow = new ImageSpan(context, R.drawable.ic_right_triangle); }
Example #23
Source File: GroupCreateActivity.java From Yahala-Messenger with MIT License | 5 votes |
public XImageSpan createAndPutChipForUser(TLRPC.User user) { LayoutInflater lf = (LayoutInflater) parentActivity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); View textView = lf.inflate(R.layout.group_create_bubble, null); TextView text = (TextView) textView.findViewById(R.id.bubble_text_view); String name = Utilities.formatName(user.first_name, user.last_name); if (name.length() == 0 && user.phone != null && user.phone.length() != 0) { name = PhoneFormat.getInstance().format("+" + user.phone); } text.setText(name + ", "); int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); textView.measure(spec, spec); textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight()); Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(b); canvas.translate(-textView.getScrollX(), -textView.getScrollY()); textView.draw(canvas); textView.setDrawingCacheEnabled(true); Bitmap cacheBmp = textView.getDrawingCache(); Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true); textView.destroyDrawingCache(); final BitmapDrawable bmpDrawable = new BitmapDrawable(b); bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight()); SpannableStringBuilder ssb = new SpannableStringBuilder(""); XImageSpan span = new XImageSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE); allSpans.add(span); selectedContacts.put(user.jid, span); for (ImageSpan sp : allSpans) { ssb.append("<<"); ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE); } userSelectEditText.setText(ssb); userSelectEditText.setSelection(ssb.length()); return span; }
Example #24
Source File: L3PostActivity.java From smart-farmer-android with Apache License 2.0 | 5 votes |
@Override public void onFaceItemClick(FacePanelView view, String face, int faceId) { View focusView = getCurrentFocus(); if (focusView != null && focusView instanceof EditText) { EditText editText = (EditText) focusView; int index = editText.getSelectionStart(); if (FacePanelView.KEY_DELETE.equals(face)) { //发送删除事件 if (index > 0) { editText.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL)); } } else { face = "{:" + face + ":}"; int size = SizeUtils.dp2px(20); Drawable drawable = getResources().getDrawable(faceId); drawable.setBounds(0, 0, size, size); ImageSpan imageSpan = new ImageSpan(drawable, ALIGN_BOTTOM); SpannableString spannableString = new SpannableString(face); spannableString.setSpan(imageSpan, 0, face.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); if (index < 0 || index >= editText.getText().length()) { editText.getEditableText().append(spannableString); } else { editText.getEditableText().insert(index, spannableString); } editText.setSelection(index + face.length()); } } }
Example #25
Source File: ColumnNameView.java From SqliteManager with Apache License 2.0 | 5 votes |
@Override public void onClick(View v) { TableNameHeaderViewTag tableNameHeaderViewTag = (TableNameHeaderViewTag) v.getTag(); byte nextSortOrder = getNextSortOrder(tableNameHeaderViewTag.sortOrder); for (int i = 0; i < getChildCount(); i++) { View currentChild = getChildAt(i); if (currentChild instanceof TextView) { ((TableNameHeaderViewTag) currentChild.getTag()).sortOrder = NO_SORT; int columnIndex = ((TableNameHeaderViewTag) currentChild.getTag()).columnIndex; ((TextView) currentChild).setText(mTableColumnNames[columnIndex]); } } boolean isAscendingOrder = nextSortOrder == ASCENDING_SORT; if (mColumnHeaderSortChangeListener != null) { mColumnHeaderSortChangeListener.onHeaderColumnSortChanged(mTableColumnNames[tableNameHeaderViewTag.columnIndex], isAscendingOrder); } tableNameHeaderViewTag.sortOrder = nextSortOrder; Drawable ascendingDescendingIcon; if (isAscendingOrder) { ascendingDescendingIcon = getContext().getResources().getDrawable(R.drawable.ic_sort_ascending_white_24dp); } else { ascendingDescendingIcon = getContext().getResources().getDrawable(R.drawable.ic_sort_descending_white_24dp); } String tableName = mTableColumnNames[tableNameHeaderViewTag.columnIndex]; Spannable spannableString = new SpannableString(tableName + " "); ascendingDescendingIcon.setBounds(0, 0, 56, 56); ImageSpan image = new ImageSpan(ascendingDescendingIcon, ImageSpan.ALIGN_BASELINE); spannableString.setSpan(image, tableName.length() + 2, spannableString.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); ((TextView) v).setText(spannableString); }
Example #26
Source File: VideoViewLiveActivity.java From MyHearts with Apache License 2.0 | 5 votes |
private SpannableStringBuilder createSpannable(Drawable drawable) { String text = "bitmap"; SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text); ImageSpan span = new ImageSpan(drawable);//ImageSpan.ALIGN_BOTTOM); spannableStringBuilder.setSpan(span, 0, text.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); spannableStringBuilder.append("图文混排"); spannableStringBuilder.setSpan(new BackgroundColorSpan(Color.parseColor("#8A2233B1")), 0, spannableStringBuilder.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); return spannableStringBuilder; }
Example #27
Source File: SmileyReader.java From AndFChat with GNU General Public License v3.0 | 5 votes |
public static Spannable addSmileys(Context context, Spannable text) { for (Entry<Pattern, Integer> entry : emoticons.entrySet()) { Matcher matcher = entry.getKey().matcher(text); while (matcher.find()) { text.setSpan(new ImageSpan(context, entry.getValue()), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } return text; }
Example #28
Source File: SearchView.java From Libraries-for-Android-Developers with MIT License | 5 votes |
private CharSequence getDecoratedHint(CharSequence hintText) { // If the field is always expanded, then don't add the search icon to the hint if (!mIconifiedByDefault) return hintText; SpannableStringBuilder ssb = new SpannableStringBuilder(" "); // for the icon ssb.append(hintText); Drawable searchIcon = getContext().getResources().getDrawable(getSearchIconId()); int textSize = (int) (mQueryTextView.getTextSize() * 1.25); searchIcon.setBounds(0, 0, textSize, textSize); ssb.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return ssb; }
Example #29
Source File: SearchView.java From zhangshangwuda with Apache License 2.0 | 5 votes |
private CharSequence getDecoratedHint(CharSequence hintText) { // If the field is always expanded, then don't add the search icon to the hint if (!mIconifiedByDefault) return hintText; SpannableStringBuilder ssb = new SpannableStringBuilder(" "); // for the icon ssb.append(hintText); Drawable searchIcon = getContext().getResources().getDrawable(getSearchIconId()); int textSize = (int) (mQueryTextView.getTextSize() * 1.25); searchIcon.setBounds(0, 0, textSize, textSize); ssb.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return ssb; }
Example #30
Source File: LikerTextView.java From TestChat with Apache License 2.0 | 5 votes |
private SpannableString setImageSpan(List<String> list) { SpannableString spannableString = new SpannableString(".."); if (list != null && list.contains(UserManager.getInstance().getCurrentUser().getObjectId())) { spannableString.setSpan(new ImageSpan(getContext(), R.drawable.ic_favorite_deep_orange_a700_24dp, DynamicDrawableSpan.ALIGN_BASELINE), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { spannableString.setSpan(new ImageSpan(getContext(), R.drawable.ic_favorite_border_deep_orange_a700_24dp, DynamicDrawableSpan.ALIGN_BASELINE), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } return spannableString; }