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

Better emoji height management #117

Merged
merged 5 commits into from
May 8, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 8 additions & 9 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_activity_root_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
xmlns:app="http://schemas.android.com/apk/res-auto"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you revert those changes?

xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_activity_root_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<android.support.v7.widget.RecyclerView
android:id="@+id/main_activity_recycler_view"
Expand Down Expand Up @@ -41,8 +41,7 @@
android:layout_weight="1"
android:imeOptions="actionSend"
android:inputType="textCapSentences|textMultiLine"
android:maxLines="3"
app:emojiSize="26sp"/>
android:maxLines="3"/>

<ImageView
android:id="@+id/main_activity_send"
Expand Down
17 changes: 8 additions & 9 deletions app/src/main/res/layout/adapter_chat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
android:orientation="vertical">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

> should go on the same line


<com.vanniktech.emoji.EmojiTextView
android:id="@+id/adapter_chat_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
tools:text="my text"
/>
<com.vanniktech.emoji.EmojiTextView
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also here please revert the white space changes

android:id="@+id/adapter_chat_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textIsSelectable="true"
tools:text="my text"/>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also here revert the /> change

</LinearLayout>
17 changes: 8 additions & 9 deletions app/src/main/res/layout/dialog_main.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_dialog_root_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainDialog">
xmlns:app="http://schemas.android.com/apk/res-auto"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main_dialog_root_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context=".MainDialog">

<android.support.v7.widget.RecyclerView
android:id="@+id/main_dialog_recycler_view"
Expand Down Expand Up @@ -39,8 +39,7 @@
android:layout_weight="1"
android:imeOptions="actionSend"
android:inputType="textCapSentences|textMultiLine"
android:maxLines="3"
app:emojiSize="26sp"/>
android:maxLines="3"/>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know what to do about this one...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup this one is okay. Sorry for the confusion


<ImageView
android:id="@+id/main_dialog_send"
Expand Down
27 changes: 4 additions & 23 deletions emoji/src/main/java/com/vanniktech/emoji/EmojiEditText.java
Original file line number Diff line number Diff line change
@@ -1,52 +1,33 @@
package com.vanniktech.emoji;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
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);
}

public EmojiEditText(final Context context, final AttributeSet attrs) {
super(context, attrs);
init(attrs);

init();
}

private void init(@Nullable final AttributeSet attrs) {
private void init() {
if (!isInEditMode()) {
EmojiManager.getInstance().verifyInstalled();
}

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

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

setText(getText());
}

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

public void setEmojiSize(final int pixels) {
emojiSize = pixels;
EmojiHandler.addEmojis(getContext(), getText(), getLineHeight());
}

public void backspace() {
Expand Down
6 changes: 6 additions & 0 deletions emoji/src/main/java/com/vanniktech/emoji/EmojiSpan.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.vanniktech.emoji;

import android.content.Context;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -30,4 +31,9 @@ final class EmojiSpan extends DynamicDrawableSpan {

return drawable;
}

@Override public int getSize(final Paint paint, final CharSequence text, final int start,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why all of the parameters if all they do is just nothing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that's the signature of the base method, so we have to specify all of these parameters.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh okay, didn't see the @Override

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method can be just deleted right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we need it to specify the size of the Span to the plattform.

final int end, final Paint.FontMetricsInt fm) {
return size;
}
}
27 changes: 4 additions & 23 deletions emoji/src/main/java/com/vanniktech/emoji/EmojiTextView.java
Original file line number Diff line number Diff line change
@@ -1,52 +1,33 @@
package com.vanniktech.emoji;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
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);
}

public EmojiTextView(final Context context, final AttributeSet attrs) {
super(context, attrs);
init(attrs);

init();
}

private void init(@Nullable final AttributeSet attrs) {
private void init() {
if (!isInEditMode()) {
EmojiManager.getInstance().verifyInstalled();
}

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

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

setText(getText());
}

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

public void setEmojiSize(final int pixels) {
emojiSize = pixels;
}
}
6 changes: 0 additions & 6 deletions emoji/src/main/res/values/attrs.xml

This file was deleted.