Java Code Examples for android.text.style.ImageSpan#ALIGN_BASELINE

The following examples show how to use android.text.style.ImageSpan#ALIGN_BASELINE . 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: FastReplyFragment.java    From ChipHellClient with Apache License 2.0 6 votes vote down vote up
private void setFace(SpannableStringBuilder spb, String smileName, int length) {
    String path = SmileTable.get(smileName);
    try {
        int height = (int) editTextFastReply.getTextSize() * 2;
        GifDrawable drawable = new GifDrawable(ChhApplication.getInstance().getAssets(), path);
        // Drawable drawable = Drawable.createFromStream(getResources().getAssets().open(path), smileName);
        drawable.setBounds(0, 0, height, height);
        ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
        SpannableString spanStr = new SpannableString(smileName);
        spanStr.setSpan(imageSpan, 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        spb.append(spanStr);
    } catch (IOException e) {
        e.printStackTrace();
        spb.append(smileName);
    }

}
 
Example 2
Source File: CatnutUtils.java    From catnut with MIT License 6 votes vote down vote up
/**
 * 微博文字转表情
 *
 * @param boundPx the icon' s rectangle bound, if zero, use the default
 */
public static SpannableString text2Emotion(Context context, String key, int boundPx) {
	SpannableString spannable = new SpannableString(key);
	InputStream inputStream = null;
	Drawable drawable = null;
	try {
		inputStream = context.getAssets().open(TweetImageSpan.EMOTIONS_DIR + TweetImageSpan.EMOTIONS.get(key));
		drawable = Drawable.createFromStream(inputStream, null);
	} catch (IOException e) {
		Log.e(TAG, "load emotion error!", e);
	} finally {
		closeIO(inputStream);
	}
	if (drawable != null) {
		if (boundPx == 0) {
			drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
		} else {
			drawable.setBounds(0, 0, boundPx, boundPx);
		}
		ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
		spannable.setSpan(span, 0, key.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
	}
	return spannable;
}
 
Example 3
Source File: TimeLineUtility.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
private static void addEmotions(SpannableString value) {
    // Paint.FontMetrics fontMetrics = mEditText.getPaint().getFontMetrics();
    // int size = (int)(fontMetrics.descent-fontMetrics.ascent);
    int size = 50;

    Map<String, Integer> smiles = SmileyMap.getInstance().getSmiles();
    Resources resources = BeeboApplication.getAppContext().getResources();

    Matcher localMatcher = EMOTION_URL.matcher(value);
    while (localMatcher.find()) {
        String key = localMatcher.group(0);
        if (smiles.containsKey(key)) {
            int k = localMatcher.start();
            int m = localMatcher.end();
            if (m - k < 8) {
                Drawable drawable = resources.getDrawable(smiles.get(key));
                if (drawable != null) {
                    drawable.setBounds(0, 0, size, size);
                }
                ImageSpan localImageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
                value.setSpan(localImageSpan, k, m, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            }
        }

    }
}
 
Example 4
Source File: PromotionsFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
private void setClaimedButton() {
  promotionAction.setEnabled(false);
  promotionAction.setBackgroundColor(getResources().getColor(R.color.grey_fog_light));
  promotionAction.setTextColor(getResources().getColor(R.color.black));

  SpannableString string = new SpannableString(
      "  " + getResources().getString(R.string.holidayspromotion_button_claimed)
          .toUpperCase());
  Drawable image =
      AppCompatResources.getDrawable(getContext(), R.drawable.ic_promotion_claimed_check);
  image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
  ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BASELINE);
  string.setSpan(imageSpan, 0, 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
  promotionAction.setTransformationMethod(null);
  promotionAction.setText(string);
}
 
Example 5
Source File: CourseDiscussionPostsActivity.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onStart() {
    super.onStart();

    if (searchQuery != null) {
        setTitle(getString(R.string.discussion_posts_search_title));
        return;
    }

    if (discussionTopic != null && discussionTopic.getName() != null) {
        if (discussionTopic.isFollowingType()) {
            SpannableString title = new SpannableString("   " + discussionTopic.getName());
            IconDrawable starIcon = new IconDrawable(this, FontAwesomeIcons.fa_star)
                    .colorRes(this, R.color.white)
                    .sizeRes(this, R.dimen.edx_base)
                    .tint(null); // IconDrawable is tinted by default, but we don't want it to be tinted here
            starIcon.setBounds(0, 0, starIcon.getIntrinsicWidth(), starIcon.getIntrinsicHeight());
            ImageSpan iSpan = new ImageSpan(starIcon, ImageSpan.ALIGN_BASELINE);
            title.setSpan(iSpan, 0, 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            setTitle(title);
        } else {
            setTitle(discussionTopic.getName());
        }
    }
}
 
Example 6
Source File: Utils.java    From MaterialQQLite with Apache License 2.0 6 votes vote down vote up
public static SpannableString getCustomFace(Context context, 
		int nResId, String strFileName) {
	if (null == context || 0 == nResId || isEmptyStr(strFileName))
		return null;
	
	String str = "/c[\"";
	str += strFileName;
	str += "\"]";
			
	ImageSpan imgSpan = new ImageSpan(context, 
			nResId, ImageSpan.ALIGN_BASELINE);
	SpannableString spanStr = new SpannableString(str);
	spanStr.setSpan(imgSpan, 0, str.length(),
			Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
	
	return spanStr;
}
 
Example 7
Source File: Utils.java    From MaterialQQLite with Apache License 2.0 6 votes vote down vote up
public static SpannableString getSysFace(Context context, 
		FaceInfo faceInfo, int cx, int cy) {
	if (null == context || null == faceInfo)
		return null;

	if (faceInfo.m_nId < 0 || 0 == faceInfo.m_nResId)
		return new SpannableString(faceInfo.m_strTip);
	
	String str = "/f[\"";
	str += faceInfo.m_nId;
	str += "\"]";

	Drawable drawable = context.getResources().getDrawable(faceInfo.m_nResId);
	drawable.setBounds(0, 0, cx, cy);
	
	ImageSpan imgSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
	SpannableString spanStr = new SpannableString(str);
	spanStr.setSpan(imgSpan, 0, str.length(),
			Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
	
	return spanStr;
}
 
Example 8
Source File: RecipientEditTextView.java    From talk-android with MIT License 5 votes vote down vote up
private int getImageSpanAlignment() {
    switch (mImageSpanAlignment) {
        case IMAGE_SPAN_ALIGNMENT_BASELINE:
            return ImageSpan.ALIGN_BASELINE;
        case IMAGE_SPAN_ALIGNMENT_BOTTOM:
            return ImageSpan.ALIGN_BOTTOM;
        default:
            return ImageSpan.ALIGN_BOTTOM;
    }
}
 
Example 9
Source File: TopicPostPresenter.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 5 votes vote down vote up
private void finishUpload(String picUrl, Uri uri) {
    String selectedImagePath2 = FunctionUtils.getPath(mBaseView.getContext(), uri);
    String spanStr = "[img]./" + picUrl + "[/img]";
    if (!StringUtils.isEmpty(selectedImagePath2)) {
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(selectedImagePath2, options);
        DisplayMetrics dm = ApplicationContextHolder.getResources().getDisplayMetrics();

        int screenWidth = (int) (dm.widthPixels * 0.75);
        int screenHeight = (int) (dm.heightPixels * 0.75);
        int width = options.outWidth;
        int height = options.outHeight;
        float scaleWidth = ((float) screenWidth) / width;
        float scaleHeight = ((float) screenHeight) / height;
        if (scaleWidth < scaleHeight && scaleWidth < 1f) {// 不能放大啊,然后主要是哪个小缩放到哪个就行了
            options.inSampleSize = (int) (1 / scaleWidth);
        } else if (scaleWidth >= scaleHeight && scaleHeight < 1f) {
            options.inSampleSize = (int) (1 / scaleHeight);
        } else {
            options.inSampleSize = 1;
        }
        options.inJustDecodeBounds = false;
        Bitmap bitmap = BitmapFactory.decodeFile(selectedImagePath2, options);
        BitmapDrawable bd = new BitmapDrawable(bitmap);
        bd.setBounds(0, 0, bd.getIntrinsicWidth(), bd.getIntrinsicHeight());
        SpannableString spanStringS = new SpannableString(spanStr);
        ImageSpan span = new ImageSpan(bd, ImageSpan.ALIGN_BASELINE);
        spanStringS.setSpan(span, 0, spanStr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        mBaseView.insertFile(selectedImagePath2, spanStringS);
    } else {
        mBaseView.insertFile(selectedImagePath2, picUrl);
    }
}
 
Example 10
Source File: Utils.java    From MaterialQQLite with Apache License 2.0 5 votes vote down vote up
public static SpannableString getCustomFace(final Context context, 
			Bitmap bmp, String strFileName, ClickableSpan clickSpan) {
		if (null == context || null == bmp || isEmptyStr(strFileName))
			return null;
		
		String str = "/c[\"";
		str += strFileName;
		str += "\"]";
		
//		int cx = bmp.getWidth();
//		int cy = bmp.getHeight();
//		
//		Drawable drawable = new BitmapDrawable(bmp);
//		drawable.setBounds(0, 0, cx, cy);
		
//		ImageSpan imgSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
		ImageSpan imgSpan = new ImageSpan(context, bmp, ImageSpan.ALIGN_BASELINE);
		SpannableString spanStr = new SpannableString(str);
		spanStr.setSpan(imgSpan, 0, str.length(),
				Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

		if (clickSpan != null) {
//	        ClickableSpan[] click_spans = spanStr.getSpans(0, str.length(), ClickableSpan.class);
//	        if (click_spans.length != 0) {
//	        	for(ClickableSpan c_span : click_spans) {
//	            	spanStr.removeSpan(c_span);
//	            }
//	        }
			spanStr.setSpan(clickSpan, 0, str.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);			
		}
        
		return spanStr;
	}
 
Example 11
Source File: ResCompat.java    From NoHttp with Apache License 2.0 5 votes vote down vote up
public static SpannableString getImageSpanText(CharSequence content, Drawable drawable, int start, int end) {
    SpannableString stringSpan = new SpannableString(content);
    setDrawableBounds(drawable);
    ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
    stringSpan.setSpan(imageSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return stringSpan;
}
 
Example 12
Source File: Smilies.java    From Atomic with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts all smilies in a string to graphical smilies.
 *
 * @param text A string with smilies.
 * @return A SpannableString with graphical smilies.
 */
public static SpannableString toSpannable(SpannableString text, Context context) {
  if( _settings == null )
    _settings = new Settings(context.getApplicationContext());
  StringBuilder regex = new StringBuilder("(");
  String[] smilies = mappings.keySet().toArray(new String[mappings.size()]);

  for( int i = 0; i < smilies.length; i++ ) {
    regex.append(Pattern.quote(smilies[i]));
    regex.append("|");
  }

  regex.deleteCharAt(regex.length() - 1);
  regex.append(")");
  Pattern smiliematcher = Pattern.compile(regex.toString());
  Matcher m = smiliematcher.matcher(text);

  while ( m.find() ) {
    //Log.d("Smilies", "SID: "+mappings.get(m.group(1)).intValue());
    //Log.d("Smilies", "OID: "+R.drawable.emoji_smile);
    Drawable smilie = context.getResources().getDrawable(mappings.get(m.group(1)).intValue());

    // We should scale the image
    int height = _settings.getFontSize();
    float density = context.getResources().getDisplayMetrics().density;
    float scale = height / (float)(smilie.getMinimumHeight());
    smilie.setBounds(0, 0, (int)(smilie.getMinimumWidth() * scale * density), (int)(height * density));
    ImageSpan span = new ImageSpan(smilie, ImageSpan.ALIGN_BASELINE);
    text.setSpan(span, m.start(), m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
  }

  return text;
}
 
Example 13
Source File: GroupCreateActivity.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
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 14
Source File: InputHelper.java    From FlowGeek with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 表情输入至文字中
 * @param resources
 * @param emotion
 * @return
 */
@SuppressWarnings("all")
public static Spannable insertEtn(Context context, EmotionRules emotion) {
    String remote = emotion.getRemote();
    Spannable spannable = new SpannableString(remote);
    Drawable d = context.getResources().getDrawable(emotion.getMResId());
    d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
    ImageSpan iSpan = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
    //Spanned.SPAN_EXCLUSIVE_EXCLUSIVE 前后输入的字符都不应用这种Spannable
    spannable.setSpan(iSpan, 0, remote.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannable;
}
 
Example 15
Source File: TextChipsEditView.java    From talk-android with MIT License 5 votes vote down vote up
private int getImageSpanAlignment() {
    switch (mImageSpanAlignment) {
        case IMAGE_SPAN_ALIGNMENT_BASELINE:
            return ImageSpan.ALIGN_BASELINE;
        case IMAGE_SPAN_ALIGNMENT_BOTTOM:
            return ImageSpan.ALIGN_BOTTOM;
        default:
            return ImageSpan.ALIGN_BOTTOM;
    }
}
 
Example 16
Source File: ColumnNameView.java    From SqliteManager with Apache License 2.0 5 votes vote down vote up
@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 17
Source File: UrlImageGetter.java    From android-discourse with Apache License 2.0 4 votes vote down vote up
@Override
public void onResponse(ImageContainer response, boolean isImmediate) {
    if (mTextView.getTag(R.id.poste_image_getter) == UrlImageGetter.this && response.getBitmap() != null) {
        BitmapDrawable drawable = new BitmapDrawable(mRes, response.getBitmap());
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        String src = response.getRequestUrl();
        // redraw the image by invalidating the container
        // 由于下面重新设置了ImageSpan,所以这里invalidate就不必要了吧
        // urlDrawable.invalidateSelf();
        // UrlImageGetter.this.mTextView.invalidate();

        // TODO 这种方式基本完美解决显示图片问题, blog?
        // 把提取到下面显示的图片在放出来? 然后点击任何图片 进入到 帖子图片浏览界面。。?
        TextView v = UrlImageGetter.this.mTextView;
        CharSequence text = v.getText();
        if (!(text instanceof Spannable)) {
            return;
        }
        Spannable spanText = (Spannable) text;
        @SuppressWarnings("unchecked") ArrayList<String> imgs = (ArrayList<String>) v.getTag(R.id.poste_image_data);
        ImageSpan[] imageSpans = spanText.getSpans(0, spanText.length(), ImageSpan.class);
        L.i("%b X Recycled %b src: %s", isImmediate, response.getBitmap().isRecycled(), src);
        for (ImageSpan imgSpan : imageSpans) {
            int start = spanText.getSpanStart(imgSpan);
            int end = spanText.getSpanEnd(imgSpan);
            L.i("%d-%d :%s", start, end, imgSpan.getSource());
            String url = imgSpan.getSource();
            url = checkUrl(url);
            if (src.equals(url)) {
                spanText.removeSpan(imgSpan);
                ImageSpan is = new ImageSpan(drawable, src, ImageSpan.ALIGN_BASELINE);
                spanText.setSpan(is, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (imgs != null && imgs.contains(src)) {
                ImageClickableSpan ics = new ImageClickableSpan(src);
                spanText.setSpan(ics, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }

        }
        v.setText(spanText);
    }

}
 
Example 18
Source File: UrlImageGetter.java    From android-discourse with Apache License 2.0 4 votes vote down vote up
@Override
protected void onPostExecute(Drawable result) {
    if (result == null) {
        // TODO 设置默认错误图片?
        return;
    }
    // set the correct bound according to the result from HTTP call
    int w = result.getIntrinsicWidth();
    int h = result.getIntrinsicHeight();
    urlDrawable.setBounds(0, 0, 0 + w, 0 + h);
    L.i("%d X %d", w, h);

    // change the reference of the current drawable to the result
    // from the HTTP call
    urlDrawable.drawable = result;

    // redraw the image by invalidating the container
    // 由于下面重新设置了ImageSpan,所以这里invalidate就不必要了吧
    // urlDrawable.invalidateSelf();
    // UrlImageGetter.this.mTextView.invalidate();

    // TODO 这种方式基本完美解决显示图片问题, blog?
    // 把提取到下面显示的图片在放出来? 然后点击任何图片 进入到 帖子图片浏览界面。。?
    TextView v = UrlImageGetter.this.mTextView;
    Spannable spanText = (Spannable) v.getText();
    @SuppressWarnings("unchecked") ArrayList<String> imgs = (ArrayList<String>) v.getTag(R.id.poste_image_data);
    ImageSpan[] imageSpans = spanText.getSpans(0, spanText.length(), ImageSpan.class);
    for (ImageSpan imgSpan : imageSpans) {
        int start = spanText.getSpanStart(imgSpan);
        int end = spanText.getSpanEnd(imgSpan);
        L.i("%d-%d :%s", start, end, imgSpan.getSource());
        if (src.equals(imgSpan.getSource())) {
            spanText.removeSpan(imgSpan);
            ImageSpan is = new ImageSpan(result, src, ImageSpan.ALIGN_BASELINE);
            spanText.setSpan(is, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        if (imgs != null && imgs.contains(src)) {
            ImageClickableSpan ics = new ImageClickableSpan(src);
            spanText.setSpan(ics, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }

    }
    // For ICS
    // UrlImageGetter.this.container.setMinimumHeight(
    // (UrlImageGetter.this.container.getHeight() + result.getIntrinsicHeight()));
    // UrlImageGetter.this.container.requestLayout();
    // UrlImageGetter.this.container.invalidate();
}
 
Example 19
Source File: PromotionAppViewHolder.java    From aptoide-client-v8 with GNU General Public License v3.0 4 votes vote down vote up
public void setApp(PromotionViewApp app, boolean isWalletInstalled) {
  setAppCardHeader(app);
  itemView.setOnClickListener(__ -> promotionAppClick.onNext(
      new PromotionAppClick(app, PromotionAppClick.ClickType.NAVIGATE)));
  promotionAction.setText(itemView.getContext()
      .getString(getButtonMessage(appState), app.getAppcValue()));

  if (!isWalletInstalled && appState != CLAIMED) {
    lockInstallButton(true);
  } else {

    if (appState == CLAIMED) {
      lockInstallButton(true);
      promotionAction.setBackground(itemView.getResources()
          .getDrawable(themeManager.getAttributeForTheme(R.attr.claimedButton).resourceId));
      promotionAction.setTextColor(
          themeManager.getAttributeForTheme(android.R.attr.textColorPrimary).data);

      SpannableString string = new SpannableString("  " + itemView.getResources()
          .getString(R.string.holidayspromotion_button_claimed)
          .toUpperCase());
      Drawable image = AppCompatResources.getDrawable(itemView.getContext(),
          R.drawable.ic_promotion_claimed_check);
      image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
      ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BASELINE);
      string.setSpan(imageSpan, 0, 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
      promotionAction.setTransformationMethod(null);
      promotionAction.setText(string);
    } else if (appState == CLAIM) {
      promotionAction.setEnabled(true);
      promotionAction.setBackgroundDrawable(itemView.getContext()
          .getResources()
          .getDrawable(R.drawable.card_border_rounded_green));
      promotionAction.setOnClickListener(
          __ -> promotionAppClick.onNext(new PromotionAppClick(app, getClickType(appState))));
    } else {
      lockInstallButton(false);
      promotionAction.setOnClickListener(
          __ -> promotionAppClick.onNext(new PromotionAppClick(app, getClickType(appState))));
    }
  }
}
 
Example 20
Source File: MessageUtils.java    From BigApp_Discuz_Android with Apache License 2.0 2 votes vote down vote up
/**
     * 处理表情
     *
     * @param context
     * @param str
     * @return
     */
    public static SpannableStringBuilder getEmoticon(final Context context, final String str, int textSize) {
        String[] emoticonTag = {"{", "}"};

        String regex = "\\{(.*?)\\}";
        SpannableStringBuilder ssb = new SpannableStringBuilder(str);

        Matcher matcher = Pattern.compile(regex).matcher(str);
        while (matcher.find()) {

            final int textStart = matcher.start() + emoticonTag[0].length();
            final int textEnd = matcher.end() - emoticonTag[1].length();

            String dir = (str).subSequence(textStart, textEnd).toString();

            String fileResDir = "file://" + SmileyUtils.getUnZipAlrightSmileyFilePath(context) + dir;
//            String fileResDir = SmileyUtils.getUnZipAlrightSmileyFilePath(context) + dir;
            ZogUtils.printLog(MessageUtils.class, "fileResDir:" + fileResDir);

            /*
            DisplayImageOptions options = ImageBaseUtils.getDefaultDisplayImageOptions();
            ImageSize targetSize = new ImageSize(40, 40); // result Bitmap will be fit to this size
            Bitmap bitmap = com.nostra13.universalimageloader.core.ImageLoader.getInstance().loadImageSync(fileResDir, targetSize, options);
            Drawable drawable = com.kit.utils.bitmap.BitmapUtils.Bitmap2Drawable(bitmap);
            */


//            Drawable drawable = ImageLoader.getInstance(context).getDrawable(dir);

//            Drawable drawable = new BitmapDrawable(BitmapFactory.decodeFile(fileResDir));
            Drawable drawable = ImageLoader.getInstance(context).getDrawable(fileResDir);

            drawable.setBounds(2, 0, textSize, textSize);


            ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
            ssb.setSpan(span, matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }


        return ssb;
    }