diff --git a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatUtilsForSettings.java b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatUtilsForSettings.java index c39c46e..1a2b696 100644 --- a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatUtilsForSettings.java +++ b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/ChatUtilsForSettings.java @@ -3,7 +3,7 @@ public class ChatUtilsForSettings { //这里设置的是UI相关,是否做到消息滚动展示在UI上,而不是全部展示,全部展示会占用大量UI资源 - private static boolean showUartLog = false; // 控制是否启用显示串口Log,这里设置是没用的(因为不是Final) + private static boolean showUartLog = false; // 控制是否启用显示串口Log private static final boolean setDebugLog = true; // 控制是否启用显示串口Log,打印在UI上(开发者使用) private static final boolean scrollingMessages = true; // 控制是否启用滚动消息功能 private static boolean clipMessages = true; // 控制是否启用剪贴板功能 @@ -16,7 +16,7 @@ public class ChatUtilsForSettings { private static boolean burnmessage = false; // 控制是否启用阅后即焚聊天功能 private static final boolean burnshowword = false; // 控制是否启用阅后即焚文字显示(后续转为用户使用,false为不需要,true为需要点击显示3秒文字) private static final boolean burnalertdialog = false; // 控制是否启用阅后即焚AliertDialog(开发者使用,false为长按消失消息,true为长按显示开发者信息) - private static final int burnwordshowtimer = 3000; // 控制阅后即焚阅读时间 + private static final int burnwordshowtimer = 3000; // 控制阅后即焚阅读时间(推荐3秒钟) private static final int burntimer = 120000; // 控制阅后即焚的时间(2分钟,120000.如为开发者推荐全局2秒钟,2000) //这里设置的是跟C代码相关的,白名单获取聊天文本,当这些文本出现在串口通讯里面的时候,提取这String后者即可,期间过滤掉前者和大量串口log。 private static final String PREFIX_SERVER = " Let's start chatting, This is the content of the server:"; diff --git a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/Emoji/Emoji.java b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/Emoji/Emoji.java new file mode 100644 index 0000000..b61d601 --- /dev/null +++ b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/Emoji/Emoji.java @@ -0,0 +1,27 @@ +package com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore.Emoji; + +public class Emoji { + private String code; + private String shortUUID; + + public Emoji(String code, String shortUUID) { + this.code = code; + this.shortUUID = shortUUID; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getShortUUID() { + return shortUUID; + } + + public void setShortUUID(String shortUUID) { + this.shortUUID = shortUUID; + } +} diff --git a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/Emoji/EmojiUtilsForCode.java b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/Emoji/EmojiUtilsForCode.java new file mode 100644 index 0000000..eaea3c6 --- /dev/null +++ b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/ChatCore/Emoji/EmojiUtilsForCode.java @@ -0,0 +1,28 @@ +package com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore.Emoji; + +public class EmojiUtilsForCode { + private Emoji[] emojis; + + public EmojiUtilsForCode() { + emojis = new Emoji[] { + + + new Emoji("U+1F600", "E00000"), // 😀 + + }; + } + + public Emoji[] getEmojis() { + return emojis; + } + + public Emoji getEmojiByShortUUID(String shortUUID) { + for (Emoji emoji : emojis) { + if (emoji.getShortUUID().equals(shortUUID)) { + return emoji; + } + } + return null; + } +} + diff --git a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/MainActivity.java b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/MainActivity.java index 68fec2f..ffbbdf6 100644 --- a/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/MainActivity.java +++ b/app/src/main/java/com/haohanyh/linmengjia/nearlink/nlchat/fun/MainActivity.java @@ -25,6 +25,7 @@ import android.provider.Settings; import android.util.Log; import android.view.KeyEvent; +import android.view.MotionEvent; import android.view.View; import android.view.WindowManager; import android.view.inputmethod.EditorInfo; @@ -116,6 +117,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe private TextView APPRunResult,MobileUSBResult,UARTResult; private EditText EditChatSendNewUI; + private long startTime; + private boolean isEmojiMode = false; + private static final int LONG_PRESS_TIME = 500; // 长按时间阈值,单位毫秒 private MaterialButton ButtonForSendData; /* TODO 1.4版本前,务必把这个TextView未参与初始化和聊天核心内容,进行修改,目前是可以正常使用了。 */ @@ -447,7 +451,35 @@ public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent EditChatSendNewUI = findViewById(id.editChatSendNewUI); EditChatSendNewUI.setOnEditorActionListener(editorActionListenerForChatSend); + View.OnTouchListener touchListenerForSend = new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + switch (motionEvent.getAction()) { + case MotionEvent.ACTION_DOWN: + startTime = System.currentTimeMillis(); + return true; + case MotionEvent.ACTION_UP: + long duration = System.currentTimeMillis() - startTime; + if (duration >= LONG_PRESS_TIME) { + isEmojiMode = true; + NearLinkChatSendEmoji(view); + } else { + if (isEmojiMode) { + isEmojiMode = false; + } + NearLinkChatSendData(view); + } + return true; + case MotionEvent.ACTION_CANCEL: + // 重置状态 + startTime = 0; + return true; + } + return false; + } + }; ButtonForSendData = findViewById(id.sendDataBtn); + ButtonForSendData.setOnTouchListener(touchListenerForSend); CheckBoxUartWarn = findViewById(id.cbUartWarn); NearLinkUartWarnToast = CheckBoxUartWarn.isChecked(); @@ -1048,28 +1080,42 @@ private String CH34xProcessingForReadData(String string) { } public void NearLinkChatSendData(View view) { - HhandlerI.sendEmptyMessage(10); - //这里写的是用户是否使用新UI和旧UI。 + //HhandlerI.sendEmptyMessage(10); + ButtonForSendData.setText(R.string.nearlinkChatSend); + byte[] to_send; String messageSend; //新UI处理发送,以字符串方式发送 - messageSend = EditChatSendNewUI.getText().toString(); - to_send = StringUtils.needProcess().toByteArrayII(EditChatSendNewUI.getText().toString()); + if (!EditChatSendNewUI.getText().toString().isEmpty()) { + messageSend = EditChatSendNewUI.getText().toString(); + to_send = StringUtils.needProcess().toByteArrayII(EditChatSendNewUI.getText().toString()); + + //byte[] to_send = StringUtils.needProcess().toByteArray(String.valueOf(EditChatSend.getText())); //以字符串方式发送 + int retval = MainAPP.CH34X.writeData(to_send, to_send.length);//写数据,第一个参数为需要发送的字节数组,第二个参数为需要发送的字节长度,返回实际发送的字节长度 + if (retval < 0) { + SnackBarToastForDebug(context,"向对方发送数据失败!","推荐重新配置",3,Snackbar.LENGTH_SHORT); + } else { + String TextOfClient = CH34xProcessingForSendData(messageSend); + + // 使用ChatUIUpdater更新UI + chatUIUpdater.updateMeUI(TextOfClient); + runOnUiThread(() -> { + //发送完消息清空待发送文本 + EditChatSendNewUI.setText(""); + }); + } + } + } - //byte[] to_send = StringUtils.needProcess().toByteArray(String.valueOf(EditChatSend.getText())); //以字符串方式发送 - int retval = MainAPP.CH34X.writeData(to_send, to_send.length);//写数据,第一个参数为需要发送的字节数组,第二个参数为需要发送的字节长度,返回实际发送的字节长度 - if (retval < 0) { - SnackBarToastForDebug(context,"向对方发送数据失败!","推荐重新配置",3,Snackbar.LENGTH_SHORT); - } else { - String TextOfClient = CH34xProcessingForSendData(messageSend); + public void NearLinkChatSendEmoji(View view) { + //HhandlerI.sendEmptyMessage(10); + ButtonForSendData.setText(R.string.nearlinkChatEmoji); - // 使用ChatUIUpdater更新UI - chatUIUpdater.updateMeUI(TextOfClient); - runOnUiThread(() -> { - //发送完消息清空待发送文本 - EditChatSendNewUI.setText(""); - }); + //todo 目前这里先这么做,后续表情包喂上来了添加 + //新UI处理发送,目前这里先这么做 + if (!EditChatSendNewUI.getText().toString().isEmpty()) { + SnackBarToastForDebug(context,"表情相关功能正在制作,敬请期待!","推荐长按返回模式",3,Snackbar.LENGTH_SHORT); } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 747b85a..28e7968 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -183,7 +183,6 @@ android:layout_height="wrap_content" android:layout_margin="5dp" android:fontFamily="sans-serif-medium" - android:onClick="NearLinkChatSendData" android:text="@string/nearlinkChatSend" android:textColor="#FFFFFFFF" app:backgroundTint="@color/Pink_is_fancy" diff --git a/app/src/main/res/layout/activity_main_phone_landscape.xml b/app/src/main/res/layout/activity_main_phone_landscape.xml index ae38254..66b65a6 100644 --- a/app/src/main/res/layout/activity_main_phone_landscape.xml +++ b/app/src/main/res/layout/activity_main_phone_landscape.xml @@ -186,7 +186,6 @@ android:layout_height="wrap_content" android:layout_margin="5dp" android:fontFamily="sans-serif-medium" - android:onClick="NearLinkChatSendData" android:text="@string/nearlinkChatSend" android:textColor="#FFFFFFFF" app:backgroundTint="@color/Pink_is_fancy" diff --git a/app/src/main/res/layout/activity_main_tablet_landscape.xml b/app/src/main/res/layout/activity_main_tablet_landscape.xml index d67fdf5..cb21b11 100644 --- a/app/src/main/res/layout/activity_main_tablet_landscape.xml +++ b/app/src/main/res/layout/activity_main_tablet_landscape.xml @@ -182,7 +182,6 @@ android:layout_height="wrap_content" android:layout_margin="5dp" android:fontFamily="sans-serif-medium" - android:onClick="NearLinkChatSendData" android:text="@string/nearlinkChatSend" android:textColor="#FFFFFFFF" app:backgroundTint="@color/Pink_is_fancy" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8f27aa4..b90e7bf 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,7 +1,7 @@ NLChat com.haohanyh.linmengjia.nearlink.nlchat.fun - 1.3.352.2024.0803 + 1.3.352.2024.0805 NLChat,浩瀚银河宗旨为用爱和魔法创造Android APP。 友情感谢 @@ -11,6 +11,7 @@ 发送消息 + 发送Emoji 星闪串口设置提示 确认开启 @@ -138,4 +139,5 @@ \n 该软件开源,二次创作等请署名\"浩瀚银河\"四字,请遵守我们公开的开源协议! + \ No newline at end of file