Java Code Examples for android.text.style.DynamicDrawableSpan

The following are top voted examples for showing how to use android.text.style.DynamicDrawableSpan. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: EasyEmoji   File: EmojiconTextView.java   Source Code and License 6 votes vote down vote up
private void init(AttributeSet attrs) {
    mEmojiconTextSize = (int) getTextSize();
    if (attrs == null) {
        mEmojiconSize = (int) getTextSize();
    } else {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon);
        mEmojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize());
        mEmojiconAlignment = a.getInt(R.styleable.Emojicon_emojiconAlignment, DynamicDrawableSpan.ALIGN_BASELINE);
        mTextStart = a.getInteger(R.styleable.Emojicon_emojiconTextStart, 0);
        mTextLength = a.getInteger(R.styleable.Emojicon_emojiconTextLength, -1);
        mUseSystemDefault = a.getBoolean(R.styleable.Emojicon_emojiconUseSystemDefault, false);
        a.recycle();
    }
    addTextChangedListener(new EmojiTextWatcher(getContext(),mEmojiconSize,mEmojiconAlignment,mEmojiconTextSize,mUseSystemDefault));
    setText(getText());
}
 
Example 2
Project: react-native-udesk   File: EmojiconSpan.java   Source Code and License 6 votes vote down vote up
public EmojiconSpan(Context context, Drawable drawable,
		int textSize) {
	super(DynamicDrawableSpan.ALIGN_BASELINE);
	mContext = context;
	mDrawable = drawable;
	mWidth = mHeight = mSize = 2 * textSize;
	mTextSize = textSize;

	if (mDrawable != null) {
		mHeight = mSize;
		mWidth = mHeight * mDrawable.getIntrinsicWidth()
				/ mDrawable.getIntrinsicHeight();
		mTop = (mTextSize - mHeight) / 2;
		mDrawable.setBounds(0, mTop, mWidth, mTop + mHeight);
	}
}
 
Example 3
Project: Emojix   File: EmojixTextWatcher.java   Source Code and License 6 votes vote down vote up
public EmojixTextWatcher(TextView textView) {
    this.textView = textView;

    SpannableString s = new SpannableString(textView.getText());
    if (!TextUtils.isEmpty(s)) {
        float textSize = textView.getTextSize();

        EmojiconHandler.addEmojis(textView.getContext(), s, (int) textSize,
                DynamicDrawableSpan.ALIGN_BASELINE, (int) textSize, 0, -1);

        textView.setText(s, TextView.BufferType.EDITABLE);

        if (textView instanceof EditText) {
            EditText editText = (EditText) textView;
            editText.setSelection(s.length());
        }
    }
}
 
Example 4
Project: RichEditText   File: RichEditText.java   Source Code and License 6 votes vote down vote up
/**
 * use local uri to insert a image
 *
 * @param uri image uri
 */
public void insertImage(Uri uri) {
    String path = UriUtils.getValidPath(getContext(), uri);
    Bitmap bitmap = bitmapCreator.getBitmapByDiskPath(path);

    SpannableString ss = new SpannableString(path);

    //construct a Drawable and set Bounds
    Drawable mDrawable = new BitmapDrawable(getContext().getResources(), bitmap);
    int width = mDrawable.getIntrinsicWidth();
    int height = mDrawable.getIntrinsicHeight();
    mDrawable.setBounds(0, 0, width > 0 ? width : 0, height > 0 ? height : 0);

    ImageSpan span = new ImageSpan(mDrawable, path, DynamicDrawableSpan.ALIGN_BOTTOM);
    ss.setSpan(span, 0, path.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    int start = this.getSelectionStart();

    getEditableText().insert(start, ss);//insert the imageSpan
    setSelection(start + ss.length());  //set selection start position
}
 
Example 5
Project: RickText   File: RichTextView.java   Source Code and License 6 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    if (isInEditMode())
        return;

    if (attrs != null) {
        TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.RichTextView);
        needNumberShow = array.getBoolean(R.styleable.RichTextView_needNumberShow, false);
        needUrlShow = array.getBoolean(R.styleable.RichTextView_needUrlShow, false);
        atColor = array.getColor(R.styleable.RichTextView_atColor, Color.BLUE);
        topicColor = array.getColor(R.styleable.RichTextView_topicColor, Color.BLUE);
        linkColor = array.getColor(R.styleable.RichTextView_linkColor, Color.BLUE);
        emojiSize = array.getInteger(R.styleable.RichTextView_emojiSize, 0);
        emojiVerticalAlignment = array.getInteger(R.styleable.RichTextView_emojiVerticalAlignment, DynamicDrawableSpan.ALIGN_BOTTOM);
        array.recycle();
    }
}
 
Example 6
Project: RickText   File: CenteredImageSpan.java   Source Code and License 6 votes vote down vote up
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom,
                 Paint paint) {

    if (mVerticalAlignment == DynamicDrawableSpan.ALIGN_BASELINE || mVerticalAlignment == DynamicDrawableSpan.ALIGN_BOTTOM) {
        super.draw(canvas, text, start, end, x, top, y, bottom, paint);
        return;
    }

    Drawable b = getDrawable();
    canvas.save();
    int transY = 0;
    //获得将要显示的文本高度-图片高度除2等居中位置+top(换行情况)
    transY = ((bottom - top) - b.getBounds().bottom) / 2 + top;
    //偏移画布后开始绘制
    canvas.translate(x, transY);
    b.draw(canvas);
    canvas.restore();
}
 
Example 7
Project: wATLlib   File: TextLayout.java   Source Code and License 6 votes vote down vote up
public void release() {
    mText = null;
    mReleased = true;
    if (lines != null)
        lines.clear();
    lineSpan = null;
    chars = null;
    for (int i = 0; i < mDynamicDrawableSpanSparseArray.size(); i++) {
        int key = mDynamicDrawableSpanSparseArray.keyAt(i);
        DynamicDrawableSpan span = mDynamicDrawableSpanSparseArray.get(key);
        Drawable dr = span.getDrawable();
        if (dr != null && dr instanceof LazyDrawable) {
            ((LazyDrawable) dr).Unload();
        }
    }
    mDynamicDrawableSpanSparseArray.clear();
}
 
Example 8
Project: vuze-remote-for-android   File: SideFilterAdapter.java   Source Code and License 6 votes vote down vote up
@Override
public void onBindFlexibleViewHolder(SideFilterViewHolder holder,
		int position) {
	SideFilterInfo item = getItem(position);
	if (item.letters.equals(FilterConstants.LETTERS_BS)) {
		Drawable drawableCompat = AndroidUtilsUI.getDrawableWithBounds(context,
				R.drawable.ic_backspace_white_24dp);
		ImageSpan imageSpan = new ImageSpan(drawableCompat,
				DynamicDrawableSpan.ALIGN_BOTTOM);
		SpannableStringBuilder ss = new SpannableStringBuilder(",");
		ss.setSpan(imageSpan, 0, 1, 0);
		holder.tvText.setText(ss);
	} else {
		holder.tvText.setText(item.letters);

		int resID = item.letters.length() > 1
				? android.R.style.TextAppearance_Small
				: android.R.style.TextAppearance_Large;
		holder.tvText.setTextAppearance(context, resID);
		holder.tvText.setTextColor(
				ContextCompat.getColor(context, R.color.login_text_color));
	}
	if (holder.tvCount != null) {
		holder.tvCount.setText(item.count > 0 ? String.valueOf(item.count) : "");
	}
}
 
Example 9
Project: XmppTest   File: EmojiTextView.java   Source Code and License 6 votes vote down vote up
private DynamicDrawableSpan getDynamicImageSpan(String content) {
	String idStr = EmojiUtil.getInstance().getFaceId(content);
	Resources resources = getContext().getResources();
	int id = resources.getIdentifier(EmojiUtil.DYNAMIC_FACE_PREFIX + idStr,
			"drawable", getContext().getPackageName());
	if (id > 0) {
		try {
			AnimatedImageSpan imageSpan = new AnimatedImageSpan(
					new AnimatedGifDrawable(getResources(),
							Math.round(getTextSize()) + 10, getResources()
									.openRawResource(id),
							new AnimatedGifDrawable.UpdateListener() {
								@Override
								public void update() {
									// update the textview
									EmojiTextView.this.postInvalidate();
								}
							}));
			return imageSpan;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	return null;
}
 
Example 10
Project: XmppTest   File: EmojiEditText.java   Source Code and License 6 votes vote down vote up
private DynamicDrawableSpan getDynamicImageSpan(String content) {
	String idStr = EmojiUtil.getInstance().getFaceId(content);
	Resources resources = getContext().getResources();
	int id = resources.getIdentifier(
			EmojiUtil.DYNAMIC_FACE_PREFIX + idStr, "drawable",
			getContext().getPackageName());
	if (id > 0) {
		try {
			AnimatedImageSpan imageSpan = new AnimatedImageSpan(
					new AnimatedGifDrawable(getResources(),
							Math.round(getTextSize()) + 10, getResources()
									.openRawResource(id), null));
			return imageSpan;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	return null;
}
 
Example 11
Project: GitHub   File: BetterImageSpan.java   Source Code and License 5 votes vote down vote up
/**
 * A helper function to allow dropping in BetterImageSpan as a replacement to ImageSpan,
 * and allowing for center alignment if passed in.
 */
public static final @BetterImageSpanAlignment
int normalizeAlignment(int alignment) {
  switch (alignment) {
    case DynamicDrawableSpan.ALIGN_BOTTOM:
      return ALIGN_BOTTOM;
    case ALIGN_CENTER:
      return ALIGN_CENTER;
    case DynamicDrawableSpan.ALIGN_BASELINE:
    default:
      return ALIGN_BASELINE;
  }
}
 
Example 12
Project: EasyEmoji   File: EmojiconEditText.java   Source Code and License 5 votes vote down vote up
private void init(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon);
    mEmojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize());
    mEmojiconAlignment = a.getInt(R.styleable.Emojicon_emojiconAlignment, DynamicDrawableSpan.ALIGN_BASELINE);
    mUseSystemDefault = a.getBoolean(R.styleable.Emojicon_emojiconUseSystemDefault, false);
    a.recycle();
    mEmojiconTextSize = (int) getTextSize();
    addTextChangedListener(new EmojiTextWatcher(getContext(),mEmojiconSize,mEmojiconAlignment,mEmojiconTextSize,mUseSystemDefault));
    setText(getText());
}
 
Example 13
Project: EasyEmoji   File: EmojiconMultiAutoCompleteTextView.java   Source Code and License 5 votes vote down vote up
private void init(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon);
    mEmojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize());
    mEmojiconAlignment = a.getInt(R.styleable.Emojicon_emojiconAlignment, DynamicDrawableSpan.ALIGN_BASELINE);
    mUseSystemDefault = a.getBoolean(R.styleable.Emojicon_emojiconUseSystemDefault, false);
    a.recycle();
    mEmojiconTextSize = (int) getTextSize();
    setText(getText());
}
 
Example 14
Project: MyFire   File: FavortListAdapter.java   Source Code and License 5 votes vote down vote up
private SpannableString setImageSpan(){
    String text = "  ";
    SpannableString imgSpanText = new SpannableString(text);
    imgSpanText.setSpan(new ImageSpan(AppApplication.getAppContext(), R.drawable.dianzansmal, DynamicDrawableSpan.ALIGN_BASELINE),
            0 , 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return imgSpanText;
}
 
Example 15
Project: TestChat   File: LikerTextView.java   Source Code and License 5 votes vote down vote up
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;
}
 
Example 16
Project: Hitalk   File: PraiseListView.java   Source Code and License 5 votes vote down vote up
private SpannableString setImageSpan(){
    String text = "  ";
    SpannableString imgSpanText = new SpannableString(text);
    imgSpanText.setSpan(new ImageSpan(HiTalkApplication.mAppContext, R.drawable.icon_praise, DynamicDrawableSpan.ALIGN_BASELINE),
            0 , 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return imgSpanText;
}
 
Example 17
Project: qmui   File: EmojiconSpan.java   Source Code and License 5 votes vote down vote up
public EmojiconSpan(Context context, int resourceId, int size, int textSize) {
    super(DynamicDrawableSpan.ALIGN_BASELINE);
    mContext = context;
    mResourceId = resourceId;
    mWidth = mHeight = mSize = size;
    mTextSize = textSize;
}
 
Example 18
Project: Pocket-Plays-for-Twitch   File: ChatAdapter.java   Source Code and License 5 votes vote down vote up
public ChatAdapter(ChatRecyclerView aRecyclerView, Activity aContext, ChatAdapterCallback aCallback) {
	messages = new ArrayList<>();
	mRecyclerView = aRecyclerView;
	context = aContext;
	mCallback = aCallback;
	settings = new Settings(context);
	linkPattern = Pattern.compile("((http|https|ftp)\\:\\/\\/[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?\\/?([a-zA-Z0\u200C123456789\\-\\._\\?\\,\\'\\/\\\\\\+&amp;%\\$#\\=~])*[^\\.\\,\\)\\(\\s])");

	emoteAlignment = DynamicDrawableSpan.ALIGN_BASELINE;
	imageMod = new ImageSpan(context, R.drawable.ic_moderator, emoteAlignment);
	imageTurbo = new ImageSpan(context, R.drawable.ic_twitch_turbo, emoteAlignment);
	isNightTheme = settings.getTheme().equals(context.getString(R.string.night_theme_name)) || settings.getTheme().equals(context.getString(R.string.true_night_theme_name));
}
 
Example 19
Project: QMUI_Android   File: EmojiconSpan.java   Source Code and License 5 votes vote down vote up
public EmojiconSpan(Context context, int resourceId, int size, int textSize) {
    super(DynamicDrawableSpan.ALIGN_BASELINE);
    mContext = context;
    mResourceId = resourceId;
    mWidth = mHeight = mSize = size;
    mTextSize = textSize;
}
 
Example 20
Project: react-native-udesk   File: EmojiconSpan.java   Source Code and License 5 votes vote down vote up
public EmojiconSpan(Context context, int resourceId, int size, int textSize) {
	super(DynamicDrawableSpan.ALIGN_BASELINE);
	mContext = context;
	mResourceId = resourceId;
	mWidth = mHeight = mSize = size;
	mTextSize = textSize;
}
 
Example 21
Project: emoticon-keyboard   File: EmojiconEditText.java   Source Code and License 5 votes vote down vote up
private void init(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon);
    mEmojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize());
    mEmojiconAlignment = a.getInt(R.styleable.Emojicon_emojiconAlignment, DynamicDrawableSpan.ALIGN_BASELINE);
    mUseSystemDefault = a.getBoolean(R.styleable.Emojicon_emojiconUseSystemDefault, false);
    a.recycle();
    mEmojiconTextSize = (int) getTextSize();
    setText(getText());
}
 
Example 22
Project: emoticon-keyboard   File: EmojiconMultiAutoCompleteTextView.java   Source Code and License 5 votes vote down vote up
private void init(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon);
    mEmojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize());
    mEmojiconAlignment = a.getInt(R.styleable.Emojicon_emojiconAlignment, DynamicDrawableSpan.ALIGN_BASELINE);
    mUseSystemDefault = a.getBoolean(R.styleable.Emojicon_emojiconUseSystemDefault, false);
    a.recycle();
    mEmojiconTextSize = (int) getTextSize();
    setText(getText());
}
 
Example 23
Project: emoticon-keyboard   File: EmojiconTextView.java   Source Code and License 5 votes vote down vote up
private void init(AttributeSet attrs) {
    mEmojiconTextSize = (int) getTextSize();
    if (attrs == null) {
        mEmojiconSize = (int) getTextSize();
    } else {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon);
        mEmojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize());
        mEmojiconAlignment = a.getInt(R.styleable.Emojicon_emojiconAlignment, DynamicDrawableSpan.ALIGN_BASELINE);
        mTextStart = a.getInteger(R.styleable.Emojicon_emojiconTextStart, 0);
        mTextLength = a.getInteger(R.styleable.Emojicon_emojiconTextLength, -1);
        mUseSystemDefault = a.getBoolean(R.styleable.Emojicon_emojiconUseSystemDefault, false);
        a.recycle();
    }
    setText(getText());
}
 
Example 24
Project: android-expression   File: ExpressionEditText.java   Source Code and License 5 votes vote down vote up
private void init(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Expression);
    mExpressionSize = (int) a.getDimension(R.styleable.Expression_expressionSize, getTextSize());
    mExpressionAlignment = a.getInt(R.styleable.Expression_expressionAlignment, DynamicDrawableSpan.ALIGN_BASELINE);
    a.recycle();
    mExpressionTextSize = (int) getTextSize();
    setText(getText());
}
 
Example 25
Project: android-expression   File: ExpressionTextView.java   Source Code and License 5 votes vote down vote up
private void init(AttributeSet attrs) {
    mExpressionTextSize = (int) getTextSize();
    if (attrs == null) {
        mExpressionSize = (int) getTextSize();
    } else {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Expression);
        mExpressionSize = (int) a.getDimension(R.styleable.Expression_expressionSize, getTextSize());
        mExpressionAlignment = a.getInt(R.styleable.Expression_expressionAlignment, DynamicDrawableSpan.ALIGN_BASELINE);
        a.recycle();
    }
    setText(getText());
}
 
Example 26
Project: ChatApp-Android   File: EmojiconEditText.java   Source Code and License 5 votes vote down vote up
private void init(AttributeSet attrs){
  TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon);
  emojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize());
  emojiconAlignment = a.getInt(R.styleable.Emojicon_emojiconAlignment, DynamicDrawableSpan
          .ALIGN_BASELINE);
  a.recycle();
  emojiconTextSize = (int) getTextSize();
  setText(getText());
}
 
Example 27
Project: ChatApp-Android   File: EmojiconMultiAutoCompleteTextView.java   Source Code and License 5 votes vote down vote up
private void init(AttributeSet attrs){
  TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon);
  emojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize());
  emojiconAlignment = a.getInt(R.styleable.Emojicon_emojiconAlignment, DynamicDrawableSpan
          .ALIGN_BASELINE);
  a.recycle();
  emojiconTextSize = (int) getTextSize();
  setText(getText());
}
 
Example 28
Project: ChatApp-Android   File: EmojiconTextView.java   Source Code and License 5 votes vote down vote up
private void init(AttributeSet attrs){
  emojiconTextSize = (int) getTextSize();
  if (attrs == null)
    emojiconSize = emojiconTextSize;
  else{
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon);
    emojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize());
    emojiconAlignment = a.getInt(R.styleable.Emojicon_emojiconAlignment,
            DynamicDrawableSpan.ALIGN_BASELINE);
    textStart = a.getInteger(R.styleable.Emojicon_emojiconTextStart, 0);
    textLength = a.getInteger(R.styleable.Emojicon_emojiconTextLength, -1);
    a.recycle();
  }
  setText(getText());
}
 
Example 29
Project: emoji-keyboard   File: EmojiTextView.java   Source Code and License 5 votes vote down vote up
private void init(AttributeSet attrs) {
    this.mEmojiTextSize = (int) this.getTextSize();
    if (attrs == null) {
        this.mEmojiSize = (int) this.getTextSize();
    } else {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emoji);
        this.mEmojiSize = (int) a.getDimension(R.styleable.Emoji_emojiSize, getTextSize());
        this.mEmojiAlignment = a.getInt(R.styleable.Emoji_emojiAlignment, DynamicDrawableSpan.ALIGN_BASELINE);
        this.mTextStart = a.getInteger(R.styleable.Emoji_emojiTextStart, 0);
        this.mTextLength = a.getInteger(R.styleable.Emoji_emojiTextLength, -1);
        this.mUseSystemDefault = a.getBoolean(R.styleable.Emoji_emojiUseSystemDefault, false);
        a.recycle();
    }
    this.setText(getText());
}
 
Example 30
Project: emoji-keyboard   File: EmojiEditText.java   Source Code and License 5 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    this.mContext = context;
    this.initFocusListener();
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emoji);
    this.mEmojiconSize = (int) a.getDimension(R.styleable.Emoji_emojiSize, getTextSize());
    this.mEmojiconAlignment = a.getInt(R.styleable.Emoji_emojiAlignment, DynamicDrawableSpan.ALIGN_BASELINE);
    this.mUseSystemDefault = a.getBoolean(R.styleable.Emoji_emojiUseSystemDefault, false);
    a.recycle();
    this.mEmojiconTextSize = (int) getTextSize();
    setText(getText());
}
 
Example 31
Project: Emojix   File: EmojixTextWatcher.java   Source Code and License 5 votes vote down vote up
@Override
public void afterTextChanged(Editable s) {
    if (start >= 0) {
        float textSize = textView.getTextSize();
        int pos = start;

        start = -2;
        EmojiconHandler.addEmojis(textView.getContext(), s, (int) textSize,
                DynamicDrawableSpan.ALIGN_BASELINE, (int) textSize, pos, count);
        start = -1;
    }
}
 
Example 32
Project: FriendCircleDemo   File: FavoriteListAdapter.java   Source Code and License 5 votes vote down vote up
private SpannableString setImageSpan() {
    String text = "  ";
    SpannableString imgSpanText = new SpannableString(text);
    imgSpanText.setSpan(new ImageSpan(mListView.getContext(), R.drawable.im_ic_dig_tips, DynamicDrawableSpan.ALIGN_BASELINE),
            0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return imgSpanText;
}
 
Example 33
Project: emojicon-master   File: EmojiconEditText.java   Source Code and License 5 votes vote down vote up
private void init(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon);
    mEmojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize());
    mEmojiconAlignment = a.getInt(R.styleable.Emojicon_emojiconAlignment, DynamicDrawableSpan.ALIGN_BASELINE);
    mUseSystemDefault = a.getBoolean(R.styleable.Emojicon_emojiconUseSystemDefault, false);
    a.recycle();
    mEmojiconTextSize = (int) getTextSize();
    setText(getText());
}
 
Example 34
Project: emojicon-master   File: EmojiconMultiAutoCompleteTextView.java   Source Code and License 5 votes vote down vote up
private void init(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon);
    mEmojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize());
    mEmojiconAlignment = a.getInt(R.styleable.Emojicon_emojiconAlignment, DynamicDrawableSpan.ALIGN_BASELINE);
    mUseSystemDefault = a.getBoolean(R.styleable.Emojicon_emojiconUseSystemDefault, false);
    a.recycle();
    mEmojiconTextSize = (int) getTextSize();
    setText(getText());
}
 
Example 35
Project: emojicon-master   File: EmojiconTextView.java   Source Code and License 5 votes vote down vote up
private void init(AttributeSet attrs) {
    mEmojiconTextSize = (int) getTextSize();
    if (attrs == null) {
        mEmojiconSize = (int) getTextSize();
    } else {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon);
        mEmojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize());
        mEmojiconAlignment = a.getInt(R.styleable.Emojicon_emojiconAlignment, DynamicDrawableSpan.ALIGN_BASELINE);
        mTextStart = a.getInteger(R.styleable.Emojicon_emojiconTextStart, 0);
        mTextLength = a.getInteger(R.styleable.Emojicon_emojiconTextLength, -1);
        mUseSystemDefault = a.getBoolean(R.styleable.Emojicon_emojiconUseSystemDefault, false);
        a.recycle();
    }
    setText(getText());
}
 
Example 36
Project: youkes_vr   File: EmojiconSpan.java   Source Code and License 5 votes vote down vote up
public EmojiconSpan(Context context, int resourceId, int size, int textSize) {
    super(DynamicDrawableSpan.ALIGN_BASELINE);
    mContext = context;
    mResourceId = resourceId;
    mWidth = mHeight = mSize = size;
    mTextSize = textSize;
}
 
Example 37
Project: umeng_community_android   File: EmojiSpan.java   Source Code and License 5 votes vote down vote up
public EmojiSpan(Context context, int resourceId, int size, int textSize) {
    super(DynamicDrawableSpan.ALIGN_BASELINE);
    mContext = context;
    mResourceId = resourceId;
    mWidth = mHeight = mSize = size;
    mTextSize = textSize;
}
 
Example 38
Project: AndroidGeek   File: EmojiSpan.java   Source Code and License 5 votes vote down vote up
public EmojiSpan(Context context, int resourceId, int size, int textSize) {
    super(DynamicDrawableSpan.ALIGN_BASELINE);
    mContext = context;
    mResourceId = resourceId;
    mWidth = mHeight = mSize = size;
    mTextSize = textSize;
}
 
Example 39
Project: wATLlib   File: SpannedSerializator.java   Source Code and License 5 votes vote down vote up
/**
 *
 * @param span
 * @param dos
 */

private void writeImageSpanData(DynamicDrawableSpan span, DataOutputStream dos) {
    Drawable d = span.getDrawable();
    Bitmap bitmap;
    if (d instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable)d).getBitmap();
    } else {
        bitmap = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(), Bitmap.Config.RGB_565);
        Canvas canvas = new Canvas(bitmap);
        d.draw(canvas);
    }
    bitmap.compress(Bitmap.CompressFormat.JPEG, 90,dos);
    bitmap.recycle();
}
 
Example 40
Project: wATLlib   File: SpannedSerializator.java   Source Code and License 5 votes vote down vote up
/**
 * by default - reads drawable from stream
 * @param dis
 * @return
 * @throws IOException
 */
protected DynamicDrawableSpan readDynamicDrawableSpan(DataInputStream dis) throws IOException, ReadError {

    // final BitmapDrawable drawable = new BitmapDrawable(null,readImageSpanData(dis));
    // DynamicDrawableSpan dds = new ImageSpan(drawable,vA);
    return readImageSpanData(dis);
}
 
Example 41
Project: wATLlib   File: TextLayout.java   Source Code and License 5 votes vote down vote up
public int getDynamicDrawablePosition(DynamicDrawableSpan span) {
    Drawable dr = span.getDrawable();
    if (dr!=null) {
        DrawableInfo di = mDrawableInfos.get(dr);
        if (di!=null) {
            return di.position;
        }
    }
    return -1;
}
 
Example 42
Project: wATLlib   File: TextLayout.java   Source Code and License 5 votes vote down vote up
/**
 * @param dds - DynamicDrawableSpan
 * @param out - Rect instance
 * @return true, if dds are visible on layout
 */

public boolean getDynamicDrawableSpanRect(DynamicDrawableSpan dds, Rect out) {
    Drawable dr = dds.getDrawable();
    if (dr != null && visibleDrawables.contains(dr)) {
        Point offset = visibleDrawableOffsets.get(dr);
        Rect bounds = visibleDrawableBounds.get(dr);
        if (out != null)
            out.set(offset.x, offset.y, offset.x + bounds.width(), offset.y + bounds.height());
        return true;
    }
    return false;
}
 
Example 43
Project: wATLlib   File: TextLayout.java   Source Code and License 5 votes vote down vote up
@Override
public void registerDrawable(DynamicDrawableSpan dds, int placement, int position) {
    Drawable dr = dds.getDrawable();
    DrawableInfo di = new DrawableInfo();
    di.span = dds;
    di.width = dr.getIntrinsicWidth();
    di.height = dr.getIntrinsicHeight();
    di.placement = placement;
    di.position = position;
    mDrawableInfos.put(dr, di);
}
 
Example 44
Project: wATLlib   File: ReflowContext.java   Source Code and License 5 votes vote down vote up
public boolean handleDefferedImages() {
    if (deffered.size() > 0) {
        LineSpan defferedSpan = deffered.remove(0);
        DynamicDrawableSpan defferedDrawableSpan = defferedSpan.getDrawable();
        return handleImage(defferedSpan, defferedDrawableSpan, false);
    }
    return true;
}
 
Example 45
Project: wATLlib   File: LineSpan.java   Source Code and License 5 votes vote down vote up
protected DynamicDrawableSpan getDrawable() {
    if (spans != null && spans.length > 0) {
        for (CharacterStyle style : spans)
            if (style instanceof DynamicDrawableSpan)
                return (DynamicDrawableSpan) style;
    }
    return null;
}
 
Example 46
Project: wATLlib   File: TextViewWS.java   Source Code and License 5 votes vote down vote up
/**
 * @param X       - touch x coord
 * @param Y       - touch y coord
 * @param longTap
 */

protected boolean processTouchAt(float X, float Y, boolean longTap, int startsFromLine) {
    int position = getOffsetForCoordinates(X, Y, startsFromLine);
    if (position > -1) {
        if (longTap && isTextSelectable()) {
            Log.v(TAG, "long tap");
            onLongTapCharacter(position);
            return true;
        }
        if (getText() instanceof Spanned) {
            ClickableSpan[] spans = ((Spanned) getText()).getSpans(position, position + 1, ClickableSpan.class);
            if (spans != null && spans.length > 0) {
                ClickableSpan cs = spans[0];
                if (cs instanceof URLSpan) {
                    if (mClickableSpanListener!=null) {
                        int css = ((Spanned)getText()).getSpanStart(cs);
                        int cse = ((Spanned)getText()).getSpanEnd(cs);
                        mClickableSpanListener.onClick(this,cs,css,cse,null);
                    } else {
                        onUrlClicked(((URLSpan) cs).getURL(), position, spans[0]);
                    }
                }
                return true;
            }
            DynamicDrawableSpan[] drawables = ((Spanned) getText()).getSpans(position, position + 1, DynamicDrawableSpan.class);
            if (drawables != null && drawables.length > 0) {
                DynamicDrawableSpan ds = drawables[0];
                onDrawableClicked(ds.getDrawable(), position, drawables[0]);
                return true;
            }
        }
    }
    postInvalidateDelayed(10);
    return false;
}
 
Example 47
Project: wATLlib   File: TextViewWS.java   Source Code and License 5 votes vote down vote up
protected void onDrawableClicked(Drawable drawable, int position, DynamicDrawableSpan dds) {
    if (mClickableSpanListener!=null) {
        int line = getLineForPosition(position);
        Rect bounds = new Rect();
        getLineBounds(line,bounds);
        getLineBounds(line,debugClickedLineBound);
        float left = getPrimaryHorizontal(line, position, textAreaWidth()) + getCompoundPaddingLeft();
        float right = getPrimaryHorizontal(line, position + 1, textAreaWidth()) + getCompoundPaddingLeft();
        bounds.left = (int) left;
        bounds.right = (int) right;
        mClickableSpanListener.onClick(this,dds,position,position+1,bounds);
    }
}
 
Example 48
Project: wATLlib   File: TextViewEx.java   Source Code and License 5 votes vote down vote up
/**
 * called by touch handler, if touched on dynamicdrawablespan
 * used internally for call DynamicDrawableInteractionListener
 * @param drawable
 * @param position
 * @param dynamicDrawableSpan
 */

@Override
protected void onDrawableClicked(Drawable drawable, int position, DynamicDrawableSpan dynamicDrawableSpan) {
    Rect bounds = new Rect();
    if (getTextLayout()!=null && getTextLayout().getDynamicDrawableSpanRect(dynamicDrawableSpan,bounds)) {
        Log.v(TAG, "clicked on drawable: '" + drawable + "' [" + bounds + "]");
    } else {
        Log.e(TAG, "clicked on invisible drawable: " + position);
    }
    mDynamicDrawableInteractionListener.onClicked(dynamicDrawableSpan,bounds,this);
}
 
Example 49
Project: emoji-lib   File: EmojiMultiAutoCompleteTextView.java   Source Code and License 5 votes vote down vote up
/**
 * Set attributes for the emoji representation
 *
 * @param attrs AttributeSet containing:
 *              emojiconSize = Display size of the emojis in pixel
 *              emojiconAlignment = Line alignment of the emojis (bottom or baseline)
 *              emojiconUseSystemDefault = Boolean indicating if system default emojis should be used
 */
private void init(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon);
    mEmojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize());
    mEmojiconAlignment = a.getInt(R.styleable.Emojicon_emojiconAlignment, DynamicDrawableSpan.ALIGN_BASELINE);
    mUseSystemDefault = a.getBoolean(R.styleable.Emojicon_emojiconUseSystemDefault, false);
    a.recycle();
    mEmojiconTextSize = (int) getTextSize();
    setText(getText());
}
 
Example 50
Project: emoji-lib   File: EmojiTextView.java   Source Code and License 5 votes vote down vote up
private void init(AttributeSet attrs) {
    mEmojiconTextSize = (int) getTextSize();
    if (attrs == null) {
        mEmojiconSize = (int) getTextSize();
    } else {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon);
        mEmojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize());
        mEmojiconAlignment = a.getInt(R.styleable.Emojicon_emojiconAlignment, DynamicDrawableSpan.ALIGN_BASELINE);
        mTextStart = a.getInteger(R.styleable.Emojicon_emojiconTextStart, 0);
        mTextLength = a.getInteger(R.styleable.Emojicon_emojiconTextLength, -1);
        mUseSystemDefault = a.getBoolean(R.styleable.Emojicon_emojiconUseSystemDefault, false);
        a.recycle();
    }
    setText(getText());
}
 
Example 51
Project: emoji-lib   File: EmojiEditText.java   Source Code and License 5 votes vote down vote up
/**
 * Set attributes for the emoji representation
 *
 * @param attrs AttributeSet containing:
 *              emojiconSize = Display size of the emojis in pixel
 *              emojiconAlignment = Line alignment of the emojis (bottom or baseline)
 *              emojiconUseSystemDefault = Boolean indicating if system default emojis should be used
 */
private void init(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon);
    mEmojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize());
    mEmojiconAlignment = a.getInt(R.styleable.Emojicon_emojiconAlignment, DynamicDrawableSpan.ALIGN_BASELINE);
    mUseSystemDefault = a.getBoolean(R.styleable.Emojicon_emojiconUseSystemDefault, false);
    a.recycle();
    mEmojiconTextSize = (int) getTextSize();
    setText(getText());
}
 
Example 52
Project: fresco   File: BetterImageSpan.java   Source Code and License 5 votes vote down vote up
/**
 * A helper function to allow dropping in BetterImageSpan as a replacement to ImageSpan,
 * and allowing for center alignment if passed in.
 */
public static final @BetterImageSpanAlignment
int normalizeAlignment(int alignment) {
  switch (alignment) {
    case DynamicDrawableSpan.ALIGN_BOTTOM:
      return ALIGN_BOTTOM;
    case ALIGN_CENTER:
      return ALIGN_CENTER;
    case DynamicDrawableSpan.ALIGN_BASELINE:
    default:
      return ALIGN_BASELINE;
  }
}
 
Example 53
Project: DominionPicker   File: ImageLibrary.java   Source Code and License 5 votes vote down vote up
/** Get an ImageSpan based off the drawable with the given value and size.
 *  @param id A unique id value will receive a unique ImageSpan instance.
 *  @return An ImageSpan for the given size and value.
 *  {@code null} if the drawable for this value and size has not been set yet. */
public synchronized ImageSpan getSpan(CharSequence value, int size, int id) {
    // Get the available sizes for the given value
    HashMap<Integer, HashMap<Integer, ImageSpan>> sizes = spans.get(value);
    if(sizes == null) {
        sizes = new HashMap<>(1);
        spans.put(value, sizes);
    }

    // Get the available instances for the given size
    HashMap<Integer, ImageSpan> instances = sizes.get(size);
    if(instances == null) {
        instances = new HashMap<>(1);
        sizes.put(size, instances);
    }

    // Return the ImageSpan with this id
    ImageSpan res = instances.get(id);
    if(res != null) return res;

    // We have no ImageSpan with that id. So lets try to make one
    Drawable d = getDrawable(value, size);
    if(d == null) return null;
    res = new ImageSpan(d, DynamicDrawableSpan.ALIGN_BOTTOM);
    instances.put(id, res);
    return res;
}
 
Example 54
Project: emojicon   File: EmojiconEditText.java   Source Code and License 5 votes vote down vote up
private void init(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon);
    mEmojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize());
    mEmojiconAlignment = a.getInt(R.styleable.Emojicon_emojiconAlignment, DynamicDrawableSpan.ALIGN_BASELINE);
    mUseSystemDefault = a.getBoolean(R.styleable.Emojicon_emojiconUseSystemDefault, false);
    a.recycle();
    mEmojiconTextSize = (int) getTextSize();
    setText(getText());
}
 
Example 55
Project: emojicon   File: EmojiconMultiAutoCompleteTextView.java   Source Code and License 5 votes vote down vote up
private void init(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon);
    mEmojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize());
    mEmojiconAlignment = a.getInt(R.styleable.Emojicon_emojiconAlignment, DynamicDrawableSpan.ALIGN_BASELINE);
    mUseSystemDefault = a.getBoolean(R.styleable.Emojicon_emojiconUseSystemDefault, false);
    a.recycle();
    mEmojiconTextSize = (int) getTextSize();
    setText(getText());
}
 
Example 56
Project: emojicon   File: EmojiconTextView.java   Source Code and License 5 votes vote down vote up
private void init(AttributeSet attrs) {
    mEmojiconTextSize = (int) getTextSize();
    if (attrs == null) {
        mEmojiconSize = (int) getTextSize();
    } else {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Emojicon);
        mEmojiconSize = (int) a.getDimension(R.styleable.Emojicon_emojiconSize, getTextSize());
        mEmojiconAlignment = a.getInt(R.styleable.Emojicon_emojiconAlignment, DynamicDrawableSpan.ALIGN_BASELINE);
        mTextStart = a.getInteger(R.styleable.Emojicon_emojiconTextStart, 0);
        mTextLength = a.getInteger(R.styleable.Emojicon_emojiconTextLength, -1);
        mUseSystemDefault = a.getBoolean(R.styleable.Emojicon_emojiconUseSystemDefault, false);
        a.recycle();
    }
    setText(getText());
}
 
Example 57
Project: sms_DualCard   File: RecipientChip.java   Source Code and License 5 votes vote down vote up
public RecipientChip(Drawable drawable, RecipientEntry entry, int offset) {
    super(drawable, DynamicDrawableSpan.ALIGN_BOTTOM);
    mDisplay = entry.getDisplayName();
    mValue = entry.getDestination().trim();
    mContactId = entry.getContactId();
    mDataId = entry.getDataId();
    mEntry = entry;
}
 
Example 58
Project: Calendar_lunar   File: RecipientChip.java   Source Code and License 5 votes vote down vote up
public RecipientChip(Drawable drawable, RecipientEntry entry, int offset) {
    super(drawable, DynamicDrawableSpan.ALIGN_BOTTOM);
    mDisplay = entry.getDisplayName();
    mValue = entry.getDestination().trim();
    mContactId = entry.getContactId();
    mDataId = entry.getDataId();
    mEntry = entry;
}
 
Example 59
Project: span   File: FImageSpanHelper.java   Source Code and License 4 votes vote down vote up
public FImageSpanHelper(DynamicDrawableSpan span)
{
    mSpan = span;
}
 
Example 60
Project: span   File: FImageSpanHelper.java   Source Code and License 4 votes vote down vote up
public DynamicDrawableSpan getSpan()
{
    return mSpan;
}