Skip to content

Commit

Permalink
修改正则表达式,fuck,android的正则语句居然不兼容POSIX字符
Browse files Browse the repository at this point in the history
  • Loading branch information
kymjs committed Aug 6, 2015
1 parent 83e2067 commit c55b698
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
5、聊天类型定义,支持文字,图片,文字+Emoji,大表情(本质是图片)。你可以自己扩展支持定位、视频、语音等。见[ChatAdapter](https://github.com/kymjs/EmojiChat/blob/master/chat/src/main/java/org/kymjs/chat/adapter/ChatAdapter.java)[KJChatKeyboard](https://github.com/kymjs/EmojiChat/blob/master/chat/src/main/java/org/kymjs/chat/widget/KJChatKeyboard.java)
6、如果你想测试大表情,请先复制[表情包](https://github.com/kymjs/EmojiChat/tree/master/bigFaceImage)中的chat文件夹(包括其中的全部表情)到SD卡根目录,并修改[ChatActivity的96行](https://github.com/kymjs/EmojiChat/blob/master/chat/src/main/java/org/kymjs/chat/ChatActivity.java)的注释与97行替换
7、8月1日更新:每个emoji表情页的最后添加删除图标。
8、8月5日更新:支持聊天内容超链接高亮以及点击链接跳到相应url中

## 关于
* QQ 群[257053751](http://jq.qq.com/?_wv=1027&k=WoM2Aa)(开发者群1),[201055521](http://jq.qq.com/?_wv=1027&k=MBVdpK)(开发者群2)<br>
Expand Down
2 changes: 1 addition & 1 deletion chat/src/main/java/org/kymjs/chat/ChatActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private void initListView() {
- (1000 * 60 * 60 * 24) * 8));
Message message1 = new Message(Message.MSG_TYPE_TEXT,
Message.MSG_STATE_SUCCESS, "Tom", "avatar", "Jerry", "avatar",
"从8月5号以后的版本支持链接高亮喔:http://www.kymjs.com 支持http、https、svn、ftp开头的链接",
"从8月5号以后的版本支持链接高亮喔:http://www.kymjs.com支持http、https、svn、ftp开头的链接",
true, true, new Date(System.currentTimeMillis() - (1000 * 60 * 60 * 24) * 8));
Message message2 = new Message(Message.MSG_TYPE_PHOTO,
Message.MSG_STATE_SUCCESS, "Tom", "avatar", "Jerry", "avatar",
Expand Down
17 changes: 11 additions & 6 deletions chat/src/main/java/org/kymjs/chat/adapter/ChatAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public ChatAdapter(Context cxt, List<Message> datas, OnChatItemClickListener lis
this.datas = datas;
kjb = new KJBitmap();
this.listener = listener;
emojitf = Typeface.createFromAsset(cxt.getAssets(), "fonts/emoji.ttf");
try {
emojitf = Typeface.createFromAsset(cxt.getAssets(), "fonts/emoji.ttf");
} catch (RuntimeException e) {
}
}

public void refresh(List<Message> datas) {
Expand Down Expand Up @@ -122,7 +125,9 @@ public View getView(final int position, View v, ViewGroup parent) {
"HH:mm:ss")));
holder.tv_date.setVisibility(View.VISIBLE);

holder.tv_chatcontent.setTypeface(emojitf);
if (emojitf != null) {
holder.tv_chatcontent.setTypeface(emojitf);
}

//如果是文本类型,则隐藏图片,如果是图片则隐藏文本
if (data.getType() == Message.MSG_TYPE_TEXT) {
Expand Down Expand Up @@ -220,10 +225,10 @@ static class ViewHolder {
*/
public static TextView handleText(TextView tv, String content) {
SpannableString sp = new SpannableString(content);

Pattern pattern = Pattern
.compile("(http|https|ftp|svn)://[\\p{Alnum}\\.]+/?\\p{Alnum}*\\??" +
"(\\p{Alnum}*=\\p{Alnum}*&?)*");
//妈蛋,又碰上一个坑,在Android中的\p{Alnum}和Java中的\p{Alnum}不是同一个值,非得要我换成[a-zA-Z0-9]才行
//这鸟问题折腾了我四五个小时,明明Java工程中运行良好,写到android中就不正常
Pattern pattern = Pattern.compile("(http|https|ftp|svn)://([a-zA-Z0-9]+[/?.?])" +
"+[a-zA-Z0-9]*\\??([a-zA-Z0-9]*=[a-zA-Z0-9]*&?)*");
Matcher matcher = pattern.matcher(content);

while (matcher.find()) {
Expand Down
9 changes: 7 additions & 2 deletions chat/src/main/java/org/kymjs/chat/widget/KJChatKeyboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,17 @@ private void initData() {
mKeyboardHelper = new SoftKeyboardStateHelper(((Activity) getContext())
.getWindow().getDecorView());
mKeyboardHelper.addSoftKeyboardStateListener(this);
emojitf = Typeface.createFromAsset(context.getAssets(), "fonts/emoji.ttf");
try {
emojitf = Typeface.createFromAsset(context.getAssets(), "fonts/emoji.ttf");
} catch (RuntimeException e) {
}
}

private void initWidget() {
mEtMsg = (EditText) findViewById(R.id.toolbox_et_message);
mEtMsg.setTypeface(emojitf);
if (emojitf != null) {
mEtMsg.setTypeface(emojitf);
}
mBtnSend = (Button) findViewById(R.id.toolbox_btn_send);
mBtnFace = (CheckBox) findViewById(R.id.toolbox_btn_face);
mBtnMore = (CheckBox) findViewById(R.id.toolbox_btn_more);
Expand Down

0 comments on commit c55b698

Please sign in to comment.