史上最简单的Emoji显示

研读了一下kymjs的EmojiChat,重点看了一下emoji显示部分,发现一个very good的地方,textview与edittext用ttf去加载emoji。
之前在写聊天对话框的时候,参考了emojicon,各种自定义textview之类的。简单说明一下原理,之所以默认文本框不能显示emoji,是因为默认字体库中没有对应的unicode编码。在文本框中显示的时候,这部分没有对应的值,就空在那边,仅仅占据几个byte位置。现在我把ttf加进去了,能不显示才怪呢。
简单的代码说明一下:在assets下面建立一个fonts文件夹,里面放入emoji.ttf,然后就剩下加载了

Typeface typeface=Typeface.createFromAsset(getAssets(), "fonts/emoji.ttf");
chat_edittext.setTypeface(typeface);
chat_textview.setTypeface(typeface);

如果要实现viewPager中的滑动,那么也仅仅需要gridview中放入相应的textview而已。

有个地方要注意一下,kymjs的EmojiChat里面有个DisplayRules类,里面用枚举对初始化表情进行管理

KJEMOJI0(0xF0, 0x9F, 0x98, 0x81)

再看下rockerhieu的emojicon,里面都是诸如

Emojicon.fromCodePoint(0x1f436)

这样的初始化,这两者之间的关系是什么?我们举个例子,一般的emoji都是4位的长度,好像这样“\u0030\u20e3”

value = new byte[]{this.value1, this.value2, this.value3, this.value4}

得到4个长度的byte数组之后,直接new String(byte)之后,就能得到这个unicode值了。

emojiIcon里面,直接通过作者提供的方法

public static final String newString(int codePoint) {
    if (Character.charCount(codePoint) == 1) {
        return String.valueOf(codePoint);
    } else {
        return new String(Character.toChars(codePoint));
    }
}

也能得到这个unicode

这个库唯一不好的地方在于,不方便自定义图标为emoji,除非手动改ttf

<div class="post-text" itemprop="text"> <p>Am developing web application using <strong>golang</strong> for web server and frontend with <strong>reactJS</strong> and <strong>nodeJS</strong> to serve the frontend. I have two issue while uploading images that are big <code>(currently am testing with 2.9 mb)</code> the <strong>first</strong> one am getting is a <strong>timeout</strong> within 10 second saying request timeout at the browser side but the upload is successfully uploaded to the database. The <strong>second</strong> issue is the request is being duplicated two times and as a result the request is saved to the database two times. I have searched on stack overflow but it doesn't seem to work. </p> <h3>First Option</h3> <p>Here is the code using ajax call i.e. fetch from isomorphic-fetch </p> <p>Following suggestion to implement a timeout wrapper at <a href="https://github.com/github/fetch/issues/175" rel="nofollow noreferrer">https://github.com/github/fetch/issues/175</a></p> <pre><code>static addEvent(events){ let config = { method: 'POST', body: events }; function timeout(ms, promise) { return new Promise(function(resolve, reject) { setTimeout(function() { reject(new Error("timeout")) }, ms) promise.then(resolve, reject) }) } return timeout(120000,fetch(`${SERVER_HOSTNAME}:${SERVER_PORT}/event`, config)) .then(function(response){ if(response.status >= 400){ return { "error":"Bad Response from Server" }; }else if(response.ok){ browserHistory.push({ pathname: '/events' }); } }); } </code></pre> <p>The request timeout still occurs within <strong>10 seconds</strong>.</p> <h3>Second Option</h3> <p>I have tried a different node module for the ajax call i.e. <strong>axios</strong> since it has a timeout option but this also didn't fix the timeout issue.</p> <h3>Third Option</h3> <p>I tried to set read timeout and write timeout on the server side similiar to <a href="https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/" rel="nofollow noreferrer">https://blog.cloudflare.com/the-complete-guide-to-golang-net-http-timeouts/</a></p> <pre><code>server := &http.Server{ Addr: ":9292", Handler: router, ReadTimeout: 180 * time.Second, WriteTimeout: 180 * time.Second, } </code></pre> <p>Again am getting request timeout at browser side within <strong>10 seconds</strong>. </p> <p>what shall I do to fix or point me if i made a mistake ?</p> </div>
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页