Skip to content

Commit

Permalink
发布2.0版本
Browse files Browse the repository at this point in the history
Signed-off-by: 7980963 <[email protected]>
  • Loading branch information
7980963 committed Jul 7, 2023
1 parent 83005cd commit 90ffea9
Show file tree
Hide file tree
Showing 35 changed files with 425 additions and 162 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,37 @@
这个项目是基于[酷安表情包](https://github.com/gddhy/coolapk-emotion)进行了大量的代码重构,,功能比原版软件强大很多。

可用作模板打包成其他表情包软件,也鼓励对本软件的二次开发,本项目使用GPL3.0开源软件协议。

## 如何快速制作属于自己的表情包软件

1. 下载项目源码,可通过GitHub的下载压缩包功能或者使用git命令

```
git clone https://github.com/7980963/Smart_Car
```
2. 下载[Android Studio](https://developer.android.google.cn/studio/),搭建好安卓开发环境
3. 项目中的app/src/main/assets为表情包存放目录,将你像要的表情包以.zip压缩包形式打包存放,表情包支持常用图片格式,长宽比最好为1:1,表情包的图片名会自动显示在图片下方(不会显示扩展名),压缩包命名格式为

```
序号_表情包名称.zip
```
其中序号为一个两位数数字。例如”01_小二柴.zip“,即是排序在第一位,表情包名为小二柴的表情包。请注意:序号必须是两位,不足请用0补齐,压缩包内不能包含目录,也不支持.rar以及tar.gz等其它格式的压缩包。
4. 项目中的app/src/main/res/mipmap为表情包的缩略图存放目录,即在表情包列表中显示的缩略图文件,命名格式为

```
image序号.gif
```
序号即为前面的压缩包序号,与前文的压缩包一一对应,支持常见的图片文件。
5. 编译项目,程序会自动根据前文所提到的文件自动生成表情包目录。

## 已知Bug

表情包列表切快了会出现报错,并且列出的表情包会出现错误,稍等几秒再重新点击即可

分享到微信的预览界面为空白,原因未知,不影响实际使用

在低版本安卓手机上(安卓9),可能会出现表情包缩略图错位,将在后面的版本修复

在低版本安卓手机上(安卓9),可能会出现加粗字体显示错误,将在后面的版本修复

狗勾我的头像与小二柴的缩略图使用了同一资源文件,删除小二柴表情包编译会出现问题,将在后面的版本修复
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "com.emoji.bread_dog"
minSdkVersion 26
targetSdk 31
versionCode 1
versionName "1.0"
versionCode 2
versionName "2.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.FileProvider"
android:authorities="com.emoji.bread_dog.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
Expand Down
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
214 changes: 214 additions & 0 deletions app/src/main/java/com/emoji/bread_dog/ButtonGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
package com.emoji.bread_dog;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.res.ResourcesCompat;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class ButtonGenerator {
private final Context context;
private final LinearLayout buttonContainer;
private final List<Button> buttons;
private Button selectedButton;
private final Toolbar toolbar;
private ImageClickListener imageClickListener;

public ButtonGenerator(Context context, LinearLayout buttonContainer, Toolbar toolbar, ImageClickListener imageClickListener) {
this.context = context;
this.buttonContainer = buttonContainer;
this.toolbar = toolbar;
this.imageClickListener = imageClickListener;
this.buttons = new ArrayList<>();
this.selectedButton = null;
}

public void generateButtons() {
String[] fileNames = getFileNamesFromAssets();
Arrays.sort(fileNames, new FileNameComparator());

for (String fileName : fileNames) {
String buttonLabel = getButtonLabel(fileName);
Drawable buttonIcon = getButtonIcon(fileName);

if (buttonLabel != null && buttonIcon != null) {
Button button = createButton(buttonLabel, buttonIcon);
addButtonClickListener(button, fileName);

buttons.add(button);
buttonContainer.addView(button);
}
}
}

private String[] getFileNamesFromAssets() {
try {
return context.getAssets().list("");
} catch (IOException e) {
e.printStackTrace();
return new String[0];
}
}

private String getButtonLabel(String fileName) {
String[] parts = fileName.split("_");
if (parts.length >= 2) {
String labelWithExtension = parts[1];
// 返回原始的文件名部分,不进行大写转换
return labelWithExtension.substring(0, labelWithExtension.lastIndexOf("."));
}
return null;
}

private Drawable getButtonIcon(String fileName) {
String[] parts = fileName.split("_");
if (parts.length >= 1) {
String sorting = parts[0];
try {
@SuppressLint("DiscouragedApi") int resourceId = context.getResources().getIdentifier("image" + sorting, "mipmap", context.getPackageName());
if (resourceId != 0) {
return ResourcesCompat.getDrawable(context.getResources(), resourceId, null);
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
return null;
}

private Button createButton(String label, Drawable icon) {
Button button = new Button(context);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
);
layoutParams.setMargins(0, 0, 0, 10);
button.setLayoutParams(layoutParams);
button.setPadding(5, 0, 0, 0);
button.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
button.setTextColor(context.getColor(android.R.color.black));
button.setAllCaps(false);

// 设置图标大小为 60x60,并居中显示
icon.setBounds(0, 0, 60, 60);
button.setCompoundDrawablesRelative(icon, null, null, null);
// 设置图标的右边距为 50
button.setCompoundDrawablePadding(50);

// 设置图标的左边距为 50
button.setPaddingRelative(50, 0, 0, 0);

button.setText(label);
button.setId(View.generateViewId());
button.setOnClickListener(v -> {
String fileName = getFileNameFromButton(button);
if (fileName != null) {
imageClickListener.onImageClick(fileName);
}
});
//设置按钮的背景
button.setBackgroundColor(Color.TRANSPARENT);

return button;
}

private void addButtonClickListener(Button button, final String fileName) {
button.setOnClickListener(v -> {
String label = getButtonLabel(fileName);
toolbar.setTitle(label);
onButtonClick(button);
if (imageClickListener != null) {
imageClickListener.onImageClick(fileName);
}
});
}


private void onButtonClick(Button button) {
if (selectedButton != null) {
//设置未选中状态背景
selectedButton.setBackgroundColor(Color.TRANSPARENT);
//设置未选中状态文字颜色
selectedButton.setTextColor(context.getColor(R.color.black));
//设置未选中状态文字普通粗细
Typeface typeface = Typeface.create(Typeface.DEFAULT, Typeface.NORMAL);
selectedButton.setTypeface(typeface);
}
selectedButton = button;
//设置选中状态背景
//selectedButton.setBackgroundColor(context.getColor(R.color.button_selected_background_color));
// 创建水波纹背景,并设置为按钮的背景
selectedButton.setBackground(AppCompatResources.getDrawable(context, R.drawable.ripple_button));

//设置选中状态文字颜色
selectedButton.setTextColor(context.getColor(R.color.button_selected_text_color));
//设置选中状态文字加粗
Typeface typeface = Typeface.create(Typeface.DEFAULT, Typeface.BOLD);
selectedButton.setTypeface(typeface);
}

private String getFileNameFromButton(Button button) {
for (Button btn : buttons) {
if (btn == button) {
String label = btn.getText().toString();
String fileName = getFileNameForLabel(label);
if (fileName != null) {
return fileName;
}
}
}
return null;
}

private String getFileNameForLabel(String label) {
String[] fileNames = getFileNamesFromAssets();
for (String fileName : fileNames) {
String buttonLabel = getButtonLabel(fileName);
if (buttonLabel != null && buttonLabel.equals(label)) {
return fileName;
}
}
return null;
}

public interface ImageClickListener {
void onImageClick(String fileName);
}

private static class FileNameComparator implements Comparator<String> {
@Override
public int compare(String fileName1, String fileName2) {
String[] parts1 = fileName1.split("_");
String[] parts2 = fileName2.split("_");
if (parts1.length >= 1 && parts2.length >= 1) {
try {
int sorting1 = Integer.parseInt(parts1[0]);
int sorting2 = Integer.parseInt(parts2[0]);
return Integer.compare(sorting1, sorting2);
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
return fileName1.compareTo(fileName2);
}
}

public void setImageClickListener(ImageClickListener imageClickListener) {
this.imageClickListener = imageClickListener;
}
}
Loading

0 comments on commit 90ffea9

Please sign in to comment.