Browse Source

dynamic emoji column span count

pull/45/head
Thodoris1999 7 years ago
parent
commit
a3eebc3e51
  1. 18
      app/src/main/java/gr/thmmy/mthmmy/utils/EmojiKeyboard.java

18
app/src/main/java/gr/thmmy/mthmmy/utils/EmojiKeyboard.java

@ -1,6 +1,7 @@
package gr.thmmy.mthmmy.utils;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.os.Handler;
import android.support.v7.widget.AppCompatImageButton;
import android.support.v7.widget.GridLayoutManager;
@ -153,7 +154,10 @@ public class EmojiKeyboard extends LinearLayout {
RecyclerView emojiRecyclerview = findViewById(R.id.emoji_recyclerview);
emojiRecyclerview.setHasFixedSize(true);
emojiRecyclerview.setLayoutManager(new GridLayoutManager(context, 6));
// TODO: More meaningful span count for grid
GridLayoutManager emojiLayoutManager = new GridLayoutManager(context, 6);
emojiLayoutManager.setSpanSizeLookup(new EmojiColumnSpanLookup());
emojiRecyclerview.setLayoutManager(emojiLayoutManager);
EmojiKeyboardAdapter emojiKeyboardAdapter = new EmojiKeyboardAdapter(emojis);
emojiKeyboardAdapter.setOnEmojiClickListener(((view, position) -> {
@ -215,4 +219,16 @@ public class EmojiKeyboard extends LinearLayout {
return bbcode;
}
}
class EmojiColumnSpanLookup extends GridLayoutManager.SpanSizeLookup {
@Override
public int getSpanSize(int position) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), emojis[position].getSrc(), options);
// TODO: piexel density sensitive column span lookup
return options.outWidth / 70 + 1;
}
}
}

Loading…
Cancel
Save