Skip to content

Commit

Permalink
🎉Release 1.3,调整部分代码结构并添加LICENSE,添加新UIdebug布局
Browse files Browse the repository at this point in the history
  • Loading branch information
Hny0305Lin committed Jul 9, 2024
1 parent 138f923 commit 6012433
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private class SentMessageHolder extends RecyclerView.ViewHolder {
timestampText = itemView.findViewById(R.id.text_message_time);

// 设置自定义字体
ChatFontUtils.applyCustomFont(context, messageText);
ChatUIFontUtils.applyCustomFont(context, messageText);
}

void bind(ChatMessage message) {
Expand All @@ -99,7 +99,7 @@ private class ReceivedMessageHolder extends RecyclerView.ViewHolder {
timestampText = itemView.findViewById(R.id.text_message_time);

// 设置自定义字体
ChatFontUtils.applyCustomFont(context, messageText);
ChatUIFontUtils.applyCustomFont(context, messageText);
}

void bind(ChatMessage message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* 受Haohanyh Computer Software Products Open Source LICENSE保护 https://github.com/Hny0305Lin/LICENSE/blob/main/LICENSE */
package com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore;

import android.content.Context;
Expand All @@ -12,7 +13,7 @@ public class ChatUIAlertDialog {

private static boolean b = true;

public static boolean show(Context context, String title, String message, CompoundButton compoundButton) {
public static boolean showNormal(Context context, String title, String message, CompoundButton compoundButton) {
new AlertDialog.Builder(context, R.style.HaohanyhDialog)
.setTitle(title)
.setMessage(message)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* 受Haohanyh Computer Software Products Open Source LICENSE保护 https://github.com/Hny0305Lin/LICENSE/blob/main/LICENSE */
package com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore;

import android.animation.ArgbEvaluator;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* 受Haohanyh Computer Software Products Open Source LICENSE保护 https://github.com/Hny0305Lin/LICENSE/blob/main/LICENSE */
package com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.view.View;

import androidx.cardview.widget.CardView;

import java.io.InputStream;

public class ChatUIBackgroundUtils {

// 设置启动时的背景
public static void setSavedBackground(Context context, View mainUIView) {
String backgroundPath = ChatFileUtils.getBackgroundPath(context);
if (backgroundPath != null) {
Uri backgroundUri = Uri.parse(backgroundPath);
try {
InputStream inputStream = context.getContentResolver().openInputStream(backgroundUri);
Drawable drawable = Drawable.createFromStream(inputStream, backgroundUri.toString());
mainUIView.setBackground(drawable);
} catch (Exception e) {
e.printStackTrace();
}
}
}

// 设置 CardView 背景为半透明
public static void setCardViewBackground(CardView cardView, int color) {
if (cardView != null) {
cardView.setBackground(new ColorDrawable(color)); // 设置半透明背景
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import android.util.Log;
import android.widget.TextView;

public class ChatFontUtils {
public class ChatUIFontUtils {

private static final String TAG = "ChatFontUtils & NLChat";

Expand All @@ -18,7 +18,7 @@ public static int getFontPathNum() {
}

public static void setFontPathNum(int fontPathNum) {
ChatFontUtils.fontPathNum = fontPathNum;
ChatUIFontUtils.fontPathNum = fontPathNum;
}

// 加载并应用自定义字体
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.hardware.usb.UsbManager;
import android.net.Uri;
Expand Down Expand Up @@ -62,6 +61,7 @@
import com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore.ChatTimestamp;
import com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore.ChatUIAlertDialog;
import com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore.ChatUIAnimationUtils;
import com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore.ChatUIBackgroundUtils;
import com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore.ChatUtils;
import com.haohanyh.linmengjia.nearlink.nlchat.fun.Premission.NearLinkChatGetSomePermission;
import com.haohanyh.linmengjia.nearlink.nlchat.fun.R.array;
Expand Down Expand Up @@ -248,6 +248,7 @@ private void Init() {
CNearlinkDev.setVisibility(View.GONE);
CTHANKS = findViewById(id.CardAPP);
CTHANKS.setVisibility(View.VISIBLE);

CNearLinkChat = findViewById(id.CardIChat);
CNearLinkChatNewUI = findViewById(id.CardIChatNewUI);
if (ChatUtils.isUiNewOrOld()) {
Expand All @@ -257,7 +258,16 @@ private void Init() {
CNearLinkChat.setVisibility(View.VISIBLE);
CNearLinkChatNewUI.setVisibility(View.GONE);
}
NearLinkNewUIUserTitle = findViewById(id.userTitleNewUI);

NearLinkNewUIUserTitle = findViewById(id.userTitleNewUI); //实现长按事件监听器,打开相册文件窗口设置背景用
NearLinkNewUIUserTitle.setOnLongClickListener(v -> {
Toast.makeText(context, "跳转相册文件中", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
pickImageLauncher.launch(intent);
return true; //返回true表示事件已处理
});

recyclerView = findViewById(id.recycler_view);
APPRunResult = findViewById(id.appResult);
MobileUSBResult = findViewById(id.mobileUsbResult);
Expand Down Expand Up @@ -367,7 +377,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
ChatUtils.setSqlitemanager(true);
SnackBarToastForDebug(context,"您已开始保存您的聊天记录啦!","目前为" + ChatUtils.isSqlitemanager(),0,Snackbar.LENGTH_SHORT);
} else {
if (ChatUIAlertDialog.show(compoundButton.getContext(), "聊天保存(SQLite)", "您确定要停止保存聊天数据吗?停止保存您的聊天,将会在接下来聊天时无法保存内容,可能会造成聊天记录丢失。", compoundButton))
if (ChatUIAlertDialog.showNormal(compoundButton.getContext(), "聊天保存(SQLite)", "您确定要停止保存聊天数据吗?停止保存您的聊天,将会在接下来聊天时无法保存内容,可能会造成聊天记录丢失。", compoundButton))
ChatUtils.setSqlitemanager(false);
SnackBarToastForDebug(context,"已为您取消保存聊天记录!","目前为" + ChatUtils.isSqlitemanager(),0,Snackbar.LENGTH_SHORT);
}
Expand All @@ -378,7 +388,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
ChatUtils.setSqliteHistory(true);
SnackBarToastForDebug(context,"您已开始展示您的聊天记录啦!","目前为" + ChatUtils.isSqliteHistory(),0,Snackbar.LENGTH_SHORT);
} else {
if (ChatUIAlertDialog.show(compoundButton.getContext(), "历史设备记录(SQLite)", "您确定要停止展示聊天数据在UI上吗?", compoundButton))
if (ChatUIAlertDialog.showNormal(compoundButton.getContext(), "历史设备记录(SQLite)", "您确定要停止展示聊天数据在UI上吗?", compoundButton))
ChatUtils.setSqliteHistory(false);
SnackBarToastForDebug(context,"已为您取消保存聊天记录!","目前为" + ChatUtils.isSqliteHistory(),0,Snackbar.LENGTH_SHORT);
}
Expand All @@ -391,7 +401,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
ChatUtils.setClipMessages(true);
SnackBarToastForDebug(context,"您已开启剪贴板功能!","目前为" + ChatUtils.isClipMessages(),0,Snackbar.LENGTH_SHORT);
} else {
if (ChatUIAlertDialog.show(compoundButton.getContext(), "聊天文本进入剪贴板", "您确定要停止剪贴板吗?剪贴板功能可以帮您自动按规则捕获内容,可以很大程度上帮助到您手动任务耗时的情况,取消则需要您自行处理屏幕上的UI信息。", compoundButton))
if (ChatUIAlertDialog.showNormal(compoundButton.getContext(), "聊天文本进入剪贴板", "您确定要停止剪贴板吗?剪贴板功能可以帮您自动按规则捕获内容,可以很大程度上帮助到您手动任务耗时的情况,取消则需要您自行处理屏幕上的UI信息。", compoundButton))
ChatUtils.setClipMessages(false);
SnackBarToastForDebug(context,"已为您取消剪贴板功能!","目前为" + ChatUtils.isClipMessages(),0,Snackbar.LENGTH_SHORT);
}
Expand Down Expand Up @@ -451,7 +461,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
if (ChatUtils.isSqliteHistory()) loadMessagesFromDatabase();

//背景处理
// 注册图片选择器的启动器
//注册图片选择器的启动器
pickImageLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
if (result.getResultCode() == RESULT_OK && result.getData() != null) {
Uri selectedImageUri = result.getData().getData();
Expand All @@ -462,45 +472,23 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {

ChatFileUtils.saveBackgroundPath(this, selectedImageUri.toString());

// 设置 CardView 背景为半透明
setCardViewBackground();
// 设置 新旧聊天卡片布局 CardView 背景为半透明
if (ChatUtils.isUiNewOrOld()) {
ChatUIBackgroundUtils.setCardViewBackground(findViewById(id.CardIChatNewUI), 0x80FFFFFF);
} else {
ChatUIBackgroundUtils.setCardViewBackground(findViewById(id.CardIChat), 0x80FFFFFF);
}
// 设置 星闪状态卡片布局 CardView 背景为75%透明
ChatUIBackgroundUtils.setCardViewBackground(findViewById(id.CardI), 0x40FFFFFF);

} catch (Exception e) {
e.printStackTrace();
}
}
});

// 实现长按事件监听器
findViewById(R.id.userTitleNewUI).setOnLongClickListener(v -> {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
pickImageLauncher.launch(intent);
return true; // 返回true表示事件已处理
});

// 设置启动时的背景
setSavedBackground();
}

private void setSavedBackground() {
String backgroundPath = ChatFileUtils.getBackgroundPath(this);
if (backgroundPath != null) {
Uri backgroundUri = Uri.parse(backgroundPath);
try {
InputStream inputStream = getContentResolver().openInputStream(backgroundUri);
Drawable drawable = Drawable.createFromStream(inputStream, backgroundUri.toString());
findViewById(R.id.MainUI).setBackground(drawable);
} catch (Exception e) {
e.printStackTrace();
}
}
}

private void setCardViewBackground() {
CardView cardView = findViewById(R.id.CardIChatNewUI);
if (cardView != null) {
cardView.setBackground(new ColorDrawable(0x80FFFFFF)); // 设置半透明背景
}
ChatUIBackgroundUtils.setSavedBackground(context, findViewById(R.id.MainUI));
}

private void InitToOpen() {
Expand Down Expand Up @@ -609,7 +597,6 @@ private void NearLinkChatReadData() {
serverMessageQueue.poll();
}
serverMessageQueue.add(processedString);
//updateServerTextView();
serverUpdater.updateTextView();
MainAPP.Vibrate(this);
} else {
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/bg_debug_bubble_log.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/newui_log_i" />
<corners android:radius="8dp" />
<padding android:left="8dp" android:top="8dp" android:right="8dp" android:bottom="8dp" />
</shape>
24 changes: 24 additions & 0 deletions app/src/main/res/layout/item_debug.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="3dp"
android:gravity="center">

<TextView
android:id="@+id/text_message_body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_debug_bubble_log"
android:gravity="top|bottom"
android:breakStrategy="simple"
android:hyphenationFrequency="none"
android:maxWidth="220dp"
android:padding="10dp"
android:text="Hello, this is a sent message! Test!"
android:textColor="@android:color/black"/>

</LinearLayout>
6 changes: 6 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@
<color name="snackbar_log_w">#CC9966</color>
<color name="snackbar_log_e">#CC0066</color>

<color name="newui_log_v">#8D090009</color>
<color name="newui_log_d">#860099FF</color>
<color name="newui_log_i">#8600CC66</color>
<color name="newui_log_e">#86CC003A</color>
<color name="newui_log_w">#86DC9854</color>

<color name="newui_time">#aaa</color>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<resources>
<string name="app_name">NLChat</string>
<string name="app_package">com.haohanyh.linmengjia.nearlink.nlchat.fun</string>
<string name="app_version">1.3.140.2024.0709</string>
<string name="app_version">1.3.148.2024.0709</string>

<string name="appwarn">NLChat,浩瀚银河宗旨为用爱和魔法创造Android APP。</string>
<string name="thanks3q">友情感谢</string>
Expand Down

0 comments on commit 6012433

Please sign in to comment.