package pingbits.com.emojikeyboard;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.style.DynamicDrawableSpan;

/**
 * Created by aagam on 7/2/15.
 */
public class EmojiSpan extends DynamicDrawableSpan {

    private final Context mContext;
    private final int mResourceId;
    private final int mSize;
    private Drawable mDrawable;

    public EmojiSpan(Context context, int resourceId, int size) {
        super();
        mContext = context;
        mResourceId = resourceId;
        mSize = size;
    }

    public Drawable getDrawable() {
        if (mDrawable == null) {
            try {
                mDrawable = mContext.getResources().getDrawable(mResourceId);
                int size = mSize;
                mDrawable.setBounds(0, 0, size, size);

            } catch (Exception e) {
                // swallow
            }
        }
        return mDrawable;
    }
}

@@ -62,16 +62,79 @@
 ontext;%0A
+import android.graphics.Canvas;%0Aimport android.graphics.Paint;%0A
 import a
@@ -194,30 +194,20 @@
 t.style.
-DynamicDrawabl
+Imag
 eSpan;%0A%0A
@@ -280,22 +280,12 @@
 nds 
-DynamicDrawabl
+Imag
 eSpa
@@ -502,16 +502,34 @@
   super(
+context,resourceId
 );%0A     
@@ -614,16 +614,30 @@
 %0A    %7D%0A%0A
+    @Override%0A
     publ
@@ -715,16 +715,67 @@
   try %7B%0A
+                mDrawable = super.getDrawable();%0A//
         
@@ -1052,11 +1052,652 @@
 e;%0A    %7D
+%0A%0A    @Override%0A    public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) %7B%0A        // adding the padding to the original image size%0A        int size = super.getSize(paint, text, start, end, fm);%0A        size += (2 * 2);%0A        return size;%0A    %7D%0A%0A    @Override%0A    public void draw(Canvas canvas, CharSequence text,%0A                     int start, int end, float x,%0A                     int top, int y, int bottom, Paint paint) %7B%0A        // adding the padding to the transformation so it will be padding on both sides%0A        super.draw(canvas, text, start, end, x, top, y, bottom, paint);%0A    %7D%0A%0A
 %0A%7D%0A

add proper padding to the emoji