-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2828f6a
commit 3849ee1
Showing
4 changed files
with
84 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,65 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
xmlns:emojicon="http://schemas.android.com/apk/res-auto" | ||
android:id="@+id/root_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
android:background="#ffffff" | ||
tools:context="momanii.hani.supernova_emoji.MainActivity"> | ||
xmlns:emojicon="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/root_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="#ffffff" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
tools:context="momanii.hani.supernova_emoji.MainActivity"> | ||
|
||
<ImageView | ||
android:id="@+id/emoji_btn" | ||
android:layout_width="40dp" | ||
android:layout_height="40dp" | ||
android:padding="4dp" | ||
android:src="@mipmap/smiley" | ||
android:layout_alignParentBottom="true" | ||
android:layout_alignParentLeft="true" | ||
android:padding="4dp" | ||
android:src="@mipmap/smiley" | ||
/> | ||
|
||
<ImageView | ||
android:id="@+id/submit_btn" | ||
android:src="@android:drawable/ic_menu_send" | ||
android:layout_width="40dp" | ||
android:layout_height="40dp" | ||
android:padding="4dp" | ||
android:layout_alignParentBottom="true" | ||
android:layout_alignParentRight="true" | ||
android:padding="4dp" | ||
android:src="@android:drawable/ic_menu_send" | ||
/> | ||
|
||
<hani.momanii.supernova_emoji_library.Helper.EmojiconEditText | ||
android:id="@+id/emojicon_edit_text" | ||
android:layout_width="match_parent" | ||
android:imeOptions="actionSend" | ||
android:inputType="text" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentBottom="true" | ||
android:layout_toRightOf="@id/emoji_btn" | ||
android:layout_toLeftOf="@id/submit_btn" | ||
emojicon:emojiconSize="28sp" /> | ||
|
||
android:layout_toRightOf="@id/emoji_btn" | ||
android:imeOptions="actionSend" | ||
android:inputType="text" | ||
emojicon:emojiconSize="28sp"/> | ||
|
||
|
||
<CheckBox | ||
android:id="@+id/use_system_default" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="Use System Default?" | ||
android:id="@+id/use_system_default" | ||
android:checked="false" | ||
android:layout_below="@+id/textView" | ||
android:layout_centerHorizontal="true" /> | ||
android:layout_centerHorizontal="true" | ||
android:checked="false" | ||
android:text="Use System Default?"/> | ||
|
||
<hani.momanii.supernova_emoji_library.Helper.EmojiconTextView | ||
android:id="@+id/textView" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerHorizontal="true" | ||
android:layout_centerVertical="true" | ||
android:layout_marginTop="26dp" | ||
android:lineSpacingExtra="17sp" | ||
android:text="Hello Emojis !" | ||
android:id="@+id/textView" | ||
android:textColor="#000000" | ||
android:textAppearance="@style/TextAppearance.AppCompat.Large" | ||
android:layout_centerVertical="true" | ||
android:layout_centerHorizontal="true" | ||
android:layout_marginTop="26dp" /> | ||
android:textColor="#000000" | ||
emojicon:emojiconAlignment="bottom"/> | ||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,37 +17,82 @@ | |
package hani.momanii.supernova_emoji_library.Helper; | ||
|
||
import android.content.Context; | ||
import android.graphics.Canvas; | ||
import android.graphics.Paint; | ||
import android.graphics.drawable.Drawable; | ||
import android.text.style.DynamicDrawableSpan; | ||
|
||
import java.lang.ref.WeakReference; | ||
|
||
/** | ||
* @author Hieu Rocker ([email protected]) | ||
* @author Hani Al Momani ([email protected]) | ||
*/ | ||
|
||
class EmojiconSpan extends DynamicDrawableSpan { | ||
private final Context mContext; | ||
|
||
private final int mResourceId; | ||
|
||
private final int mSize; | ||
|
||
private final int mTextSize; | ||
|
||
private int mHeight; | ||
|
||
private int mWidth; | ||
|
||
private int mTop; | ||
|
||
private Drawable mDrawable; | ||
|
||
public EmojiconSpan(Context context, int resourceId, int size) { | ||
super(); | ||
private WeakReference<Drawable> mDrawableRef; | ||
|
||
public EmojiconSpan(Context context, int resourceId, int size, int alignment, int textSize) { | ||
super(alignment); | ||
mContext = context; | ||
mResourceId = resourceId; | ||
mSize = size; | ||
mWidth = mHeight = mSize = size; | ||
mTextSize = textSize; | ||
} | ||
|
||
public Drawable getDrawable() { | ||
if (mDrawable == null) { | ||
try { | ||
mDrawable = mContext.getResources().getDrawable(mResourceId); | ||
int size = mSize; | ||
mDrawable.setBounds(0, 0, size, size); | ||
mHeight = mSize; | ||
mWidth = mHeight * mDrawable.getIntrinsicWidth() / mDrawable.getIntrinsicHeight(); | ||
mTop = (mTextSize - mHeight) / 2; | ||
mDrawable.setBounds(0, mTop, mWidth, mTop + mHeight); | ||
} catch (Exception e) { | ||
|
||
// swallow | ||
} | ||
} | ||
return mDrawable; | ||
} | ||
|
||
@Override | ||
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int | ||
y, int bottom, Paint paint) { | ||
//super.draw(canvas, text, start, end, x, top, y, bottom, paint); | ||
Drawable b = getCachedDrawable(); | ||
canvas.save(); | ||
|
||
int transY = bottom - b.getBounds().bottom; | ||
if (mVerticalAlignment == ALIGN_BASELINE) { | ||
transY = top + ((bottom - top) / 2) - ((b.getBounds().bottom - b.getBounds().top) / | ||
2) - mTop; | ||
} | ||
|
||
canvas.translate(x, transY); | ||
b.draw(canvas); | ||
canvas.restore(); | ||
} | ||
|
||
private Drawable getCachedDrawable() { | ||
if (mDrawableRef == null || mDrawableRef.get() == null) { | ||
mDrawableRef = new WeakReference<Drawable>(getDrawable()); | ||
} | ||
return mDrawableRef.get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters