Skip to content

Commit

Permalink
🎉Release 1.3,长按新UI文字标题可修改背景图片(BETA)
Browse files Browse the repository at this point in the history
🎉Release 1.3,长按新UI文字标题可修改背景图片(BETA)
  • Loading branch information
Hny0305Lin authored Jul 8, 2024
2 parents 5b058b1 + 7c6b9f9 commit 0d619eb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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 @@ -53,6 +54,7 @@
import com.google.android.material.snackbar.Snackbar;
import com.haohanyh.linmengjia.nearlink.nlchat.ch34x.CH34xUARTDriver;
import com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore.ChatAdapter;
import com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore.ChatFileUtils;
import com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore.ChatMessage;
import com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore.ChatMessageQueueUpdater;
import com.haohanyh.linmengjia.nearlink.nlchat.fun.ChatCore.ChatProcessorForExtract;
Expand Down Expand Up @@ -80,6 +82,7 @@
import java.util.Objects;
import java.util.Queue;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {
//Log需要的TAG
private static final String TAG = "MainActivity & NLChat";
Expand Down Expand Up @@ -458,6 +461,11 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
InputStream inputStream = getContentResolver().openInputStream(selectedImageUri);
Drawable drawable = Drawable.createFromStream(inputStream, selectedImageUri.toString());
findViewById(R.id.MainUI).setBackground(drawable);

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

// 设置 CardView 背景为半透明
setCardViewBackground();
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -471,6 +479,30 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
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)); // 设置半透明背景
}
}

private void InitToOpen() {
Expand Down
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.102.2024.0708</string>
<string name="app_version">1.3.106.2024.0708</string>

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

0 comments on commit 0d619eb

Please sign in to comment.