Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add back Emoji Size and use line height as the default. #146

Merged
merged 1 commit into from
Jun 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion emoji/src/main/java/com/vanniktech/emoji/EmojiButton.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.vanniktech.emoji;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.CallSuper;
import android.support.annotation.Px;
import android.support.v7.widget.AppCompatButton;
import android.text.SpannableStringBuilder;
import android.util.AttributeSet;

public class EmojiButton extends AppCompatButton {
private int emojiSize;

public EmojiButton(final Context context) {
this(context, null);
}
Expand All @@ -19,12 +23,29 @@ public EmojiButton(final Context context, final AttributeSet attrs) {
}

setText(getText());

if (attrs == null) {
emojiSize = getLineHeight();
} else {
final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.emoji);

try {
emojiSize = (int) a.getDimension(R.styleable.emoji_emojiSize, getLineHeight());
} finally {
a.recycle();
}
}
}

@Override @CallSuper public void setText(final CharSequence rawText, final BufferType type) {
final CharSequence text = rawText == null ? "" : rawText;
final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
EmojiHandler.replaceWithImages(getContext(), spannableStringBuilder, getLineHeight());
EmojiHandler.replaceWithImages(getContext(), spannableStringBuilder, emojiSize);
super.setText(spannableStringBuilder, type);
}

public void setEmojiSize(@Px final int pixels) {
emojiSize = pixels;
setText(getText()); // Update it.
}
}
23 changes: 22 additions & 1 deletion emoji/src/main/java/com/vanniktech/emoji/EmojiEditText.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.vanniktech.emoji;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.CallSuper;
import android.support.annotation.Px;
import android.support.v7.widget.AppCompatEditText;
import android.util.AttributeSet;
import android.view.KeyEvent;
import com.vanniktech.emoji.emoji.Emoji;

public class EmojiEditText extends AppCompatEditText {
private int emojiSize;

public EmojiEditText(final Context context) {
this(context, null);
}
Expand All @@ -20,10 +24,22 @@ public EmojiEditText(final Context context, final AttributeSet attrs) {
}

setText(getText());

if (attrs == null) {
emojiSize = getLineHeight();
} else {
final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.emoji);

try {
emojiSize = (int) a.getDimension(R.styleable.emoji_emojiSize, getLineHeight());
} finally {
a.recycle();
}
}
}

@Override @CallSuper protected void onTextChanged(final CharSequence text, final int start, final int lengthBefore, final int lengthAfter) {
EmojiHandler.replaceWithImages(getContext(), getText(), getLineHeight());
EmojiHandler.replaceWithImages(getContext(), getText(), emojiSize);
}

@CallSuper public void backspace() {
Expand All @@ -43,4 +59,9 @@ public EmojiEditText(final Context context, final AttributeSet attrs) {
}
}
}

public void setEmojiSize(@Px final int pixels) {
emojiSize = pixels;
setText(getText()); // Update it.
}
}
23 changes: 22 additions & 1 deletion emoji/src/main/java/com/vanniktech/emoji/EmojiTextView.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.vanniktech.emoji;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.CallSuper;
import android.support.annotation.Px;
import android.support.v7.widget.AppCompatTextView;
import android.text.SpannableStringBuilder;
import android.util.AttributeSet;

public class EmojiTextView extends AppCompatTextView {
private int emojiSize;

public EmojiTextView(final Context context) {
this(context, null);
}
Expand All @@ -19,12 +23,29 @@ public EmojiTextView(final Context context, final AttributeSet attrs) {
}

setText(getText());

if (attrs == null) {
emojiSize = getLineHeight();
} else {
final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.emoji);

try {
emojiSize = (int) a.getDimension(R.styleable.emoji_emojiSize, getLineHeight());
} finally {
a.recycle();
}
}
}

@Override @CallSuper public void setText(final CharSequence rawText, final BufferType type) {
final CharSequence text = rawText == null ? "" : rawText;
final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
EmojiHandler.replaceWithImages(getContext(), spannableStringBuilder, getLineHeight());
EmojiHandler.replaceWithImages(getContext(), spannableStringBuilder, emojiSize);
super.setText(spannableStringBuilder, type);
}

public void setEmojiSize(@Px final int pixels) {
emojiSize = pixels;
setText(getText()); // Update it.
}
}
6 changes: 6 additions & 0 deletions emoji/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="emoji">
<attr name="emojiSize" format="dimension"/>
</declare-styleable>
</resources>